{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Please run those two cells before running the Notebook!\n",
    "\n",
    "As those plotting settings are standard throughout the book, we do not show them in the book every time we plot something."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-29T10:48:06.120195Z",
     "start_time": "2020-01-29T10:48:05.814125Z"
    }
   },
   "outputs": [],
   "source": [
    "# %matplotlib inline\n",
    "%config InlineBackend.figure_format = \"retina\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-29T10:48:13.141309Z",
     "start_time": "2020-01-29T10:48:13.137453Z"
    }
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "import warnings\n",
    "from pandas.core.common import SettingWithCopyWarning\n",
    "warnings.simplefilter(action=\"ignore\", category=FutureWarning)\n",
    "warnings.simplefilter(action=\"ignore\", category=SettingWithCopyWarning)\n",
    "\n",
    "# feel free to modify, for example, change the context to \"notebook\"\n",
    "sns.set_theme(context=\"talk\", style=\"whitegrid\", \n",
    "              palette=\"colorblind\", color_codes=True, \n",
    "              rc={\"figure.figsize\": [12, 8]})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 1 - Acquiring Financial Data "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.1 Getting data from Yahoo Finance"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Import the libraries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-17T23:26:32.940680Z",
     "start_time": "2020-01-17T23:26:31.807352Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import yfinance as yf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Download the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-17T23:26:33.877155Z",
     "start_time": "2020-01-17T23:26:33.576806Z"
    }
   },
   "outputs": [],
   "source": [
    "df = yf.download(\"AAPL\", \n",
    "                 start=\"2011-01-01\", \n",
    "                 end=\"2021-12-31\",\n",
    "                 progress=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Inspect the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-17T23:26:38.561800Z",
     "start_time": "2020-01-17T23:26:38.541896Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloaded 2769 rows of data.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Adj Close</th>\n",
       "      <th>Volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2010-12-31</th>\n",
       "      <td>11.533929</td>\n",
       "      <td>11.552857</td>\n",
       "      <td>11.475357</td>\n",
       "      <td>11.520000</td>\n",
       "      <td>9.849808</td>\n",
       "      <td>193508000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-03</th>\n",
       "      <td>11.630000</td>\n",
       "      <td>11.795000</td>\n",
       "      <td>11.601429</td>\n",
       "      <td>11.770357</td>\n",
       "      <td>10.063869</td>\n",
       "      <td>445138400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-04</th>\n",
       "      <td>11.872857</td>\n",
       "      <td>11.875000</td>\n",
       "      <td>11.719643</td>\n",
       "      <td>11.831786</td>\n",
       "      <td>10.116392</td>\n",
       "      <td>309080800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-05</th>\n",
       "      <td>11.769643</td>\n",
       "      <td>11.940714</td>\n",
       "      <td>11.767857</td>\n",
       "      <td>11.928571</td>\n",
       "      <td>10.199142</td>\n",
       "      <td>255519600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-06</th>\n",
       "      <td>11.954286</td>\n",
       "      <td>11.973214</td>\n",
       "      <td>11.889286</td>\n",
       "      <td>11.918929</td>\n",
       "      <td>10.190896</td>\n",
       "      <td>300428800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-23</th>\n",
       "      <td>175.850006</td>\n",
       "      <td>176.850006</td>\n",
       "      <td>175.270004</td>\n",
       "      <td>176.279999</td>\n",
       "      <td>175.797409</td>\n",
       "      <td>68356600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-27</th>\n",
       "      <td>177.089996</td>\n",
       "      <td>180.419998</td>\n",
       "      <td>177.070007</td>\n",
       "      <td>180.330002</td>\n",
       "      <td>179.836319</td>\n",
       "      <td>74919600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-28</th>\n",
       "      <td>180.160004</td>\n",
       "      <td>181.330002</td>\n",
       "      <td>178.529999</td>\n",
       "      <td>179.289993</td>\n",
       "      <td>178.799149</td>\n",
       "      <td>79144300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-29</th>\n",
       "      <td>179.330002</td>\n",
       "      <td>180.630005</td>\n",
       "      <td>178.139999</td>\n",
       "      <td>179.380005</td>\n",
       "      <td>178.888916</td>\n",
       "      <td>62348900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-30</th>\n",
       "      <td>179.470001</td>\n",
       "      <td>180.570007</td>\n",
       "      <td>178.089996</td>\n",
       "      <td>178.199997</td>\n",
       "      <td>177.712143</td>\n",
       "      <td>59773000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2769 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Open        High         Low       Close   Adj Close  \\\n",
       "Date                                                                     \n",
       "2010-12-31   11.533929   11.552857   11.475357   11.520000    9.849808   \n",
       "2011-01-03   11.630000   11.795000   11.601429   11.770357   10.063869   \n",
       "2011-01-04   11.872857   11.875000   11.719643   11.831786   10.116392   \n",
       "2011-01-05   11.769643   11.940714   11.767857   11.928571   10.199142   \n",
       "2011-01-06   11.954286   11.973214   11.889286   11.918929   10.190896   \n",
       "...                ...         ...         ...         ...         ...   \n",
       "2021-12-23  175.850006  176.850006  175.270004  176.279999  175.797409   \n",
       "2021-12-27  177.089996  180.419998  177.070007  180.330002  179.836319   \n",
       "2021-12-28  180.160004  181.330002  178.529999  179.289993  178.799149   \n",
       "2021-12-29  179.330002  180.630005  178.139999  179.380005  178.888916   \n",
       "2021-12-30  179.470001  180.570007  178.089996  178.199997  177.712143   \n",
       "\n",
       "               Volume  \n",
       "Date                   \n",
       "2010-12-31  193508000  \n",
       "2011-01-03  445138400  \n",
       "2011-01-04  309080800  \n",
       "2011-01-05  255519600  \n",
       "2011-01-06  300428800  \n",
       "...               ...  \n",
       "2021-12-23   68356600  \n",
       "2021-12-27   74919600  \n",
       "2021-12-28   79144300  \n",
       "2021-12-29   62348900  \n",
       "2021-12-30   59773000  \n",
       "\n",
       "[2769 rows x 6 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(f\"Downloaded {len(df)} rows of data.\")\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also use the `Ticker` class to download the historical prices and much more."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# instantiate the Ticker class\n",
    "aapl_data = yf.Ticker(\"AAPL\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-03-28</th>\n",
       "      <td>172.169998</td>\n",
       "      <td>175.729996</td>\n",
       "      <td>172.000000</td>\n",
       "      <td>175.600006</td>\n",
       "      <td>90371900</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-03-29</th>\n",
       "      <td>176.690002</td>\n",
       "      <td>179.009995</td>\n",
       "      <td>176.339996</td>\n",
       "      <td>178.960007</td>\n",
       "      <td>100589400</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-03-30</th>\n",
       "      <td>178.550003</td>\n",
       "      <td>179.610001</td>\n",
       "      <td>176.699997</td>\n",
       "      <td>177.770004</td>\n",
       "      <td>92633200</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-03-31</th>\n",
       "      <td>177.839996</td>\n",
       "      <td>178.029999</td>\n",
       "      <td>174.399994</td>\n",
       "      <td>174.610001</td>\n",
       "      <td>103049300</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-01</th>\n",
       "      <td>174.029999</td>\n",
       "      <td>174.880005</td>\n",
       "      <td>171.940002</td>\n",
       "      <td>174.309998</td>\n",
       "      <td>78699800</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-04</th>\n",
       "      <td>174.570007</td>\n",
       "      <td>178.490005</td>\n",
       "      <td>174.440002</td>\n",
       "      <td>178.440002</td>\n",
       "      <td>76468400</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-05</th>\n",
       "      <td>177.500000</td>\n",
       "      <td>178.300003</td>\n",
       "      <td>174.419998</td>\n",
       "      <td>175.059998</td>\n",
       "      <td>73401800</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-06</th>\n",
       "      <td>172.360001</td>\n",
       "      <td>173.630005</td>\n",
       "      <td>170.130005</td>\n",
       "      <td>171.830002</td>\n",
       "      <td>89058800</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-07</th>\n",
       "      <td>171.160004</td>\n",
       "      <td>173.360001</td>\n",
       "      <td>169.850006</td>\n",
       "      <td>172.139999</td>\n",
       "      <td>77594700</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-08</th>\n",
       "      <td>171.779999</td>\n",
       "      <td>171.779999</td>\n",
       "      <td>169.199997</td>\n",
       "      <td>170.089996</td>\n",
       "      <td>76515900</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-11</th>\n",
       "      <td>168.710007</td>\n",
       "      <td>169.029999</td>\n",
       "      <td>165.500000</td>\n",
       "      <td>165.750000</td>\n",
       "      <td>72246700</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-12</th>\n",
       "      <td>168.020004</td>\n",
       "      <td>169.869995</td>\n",
       "      <td>166.639999</td>\n",
       "      <td>167.660004</td>\n",
       "      <td>79265200</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-13</th>\n",
       "      <td>167.389999</td>\n",
       "      <td>171.039993</td>\n",
       "      <td>166.770004</td>\n",
       "      <td>170.399994</td>\n",
       "      <td>70618900</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-14</th>\n",
       "      <td>170.619995</td>\n",
       "      <td>171.270004</td>\n",
       "      <td>165.039993</td>\n",
       "      <td>165.289993</td>\n",
       "      <td>75237500</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-18</th>\n",
       "      <td>163.919998</td>\n",
       "      <td>166.600006</td>\n",
       "      <td>163.570007</td>\n",
       "      <td>165.070007</td>\n",
       "      <td>69023900</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-19</th>\n",
       "      <td>165.020004</td>\n",
       "      <td>167.820007</td>\n",
       "      <td>163.910004</td>\n",
       "      <td>167.399994</td>\n",
       "      <td>67723800</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-20</th>\n",
       "      <td>168.759995</td>\n",
       "      <td>168.880005</td>\n",
       "      <td>166.100006</td>\n",
       "      <td>167.229996</td>\n",
       "      <td>67929800</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-21</th>\n",
       "      <td>168.910004</td>\n",
       "      <td>171.529999</td>\n",
       "      <td>165.910004</td>\n",
       "      <td>166.419998</td>\n",
       "      <td>87227800</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-22</th>\n",
       "      <td>166.460007</td>\n",
       "      <td>167.869995</td>\n",
       "      <td>161.500000</td>\n",
       "      <td>161.789993</td>\n",
       "      <td>84775200</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-25</th>\n",
       "      <td>161.119995</td>\n",
       "      <td>163.169998</td>\n",
       "      <td>158.460007</td>\n",
       "      <td>162.880005</td>\n",
       "      <td>92824080</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Open        High         Low       Close     Volume  \\\n",
       "Date                                                                    \n",
       "2022-03-28  172.169998  175.729996  172.000000  175.600006   90371900   \n",
       "2022-03-29  176.690002  179.009995  176.339996  178.960007  100589400   \n",
       "2022-03-30  178.550003  179.610001  176.699997  177.770004   92633200   \n",
       "2022-03-31  177.839996  178.029999  174.399994  174.610001  103049300   \n",
       "2022-04-01  174.029999  174.880005  171.940002  174.309998   78699800   \n",
       "2022-04-04  174.570007  178.490005  174.440002  178.440002   76468400   \n",
       "2022-04-05  177.500000  178.300003  174.419998  175.059998   73401800   \n",
       "2022-04-06  172.360001  173.630005  170.130005  171.830002   89058800   \n",
       "2022-04-07  171.160004  173.360001  169.850006  172.139999   77594700   \n",
       "2022-04-08  171.779999  171.779999  169.199997  170.089996   76515900   \n",
       "2022-04-11  168.710007  169.029999  165.500000  165.750000   72246700   \n",
       "2022-04-12  168.020004  169.869995  166.639999  167.660004   79265200   \n",
       "2022-04-13  167.389999  171.039993  166.770004  170.399994   70618900   \n",
       "2022-04-14  170.619995  171.270004  165.039993  165.289993   75237500   \n",
       "2022-04-18  163.919998  166.600006  163.570007  165.070007   69023900   \n",
       "2022-04-19  165.020004  167.820007  163.910004  167.399994   67723800   \n",
       "2022-04-20  168.759995  168.880005  166.100006  167.229996   67929800   \n",
       "2022-04-21  168.910004  171.529999  165.910004  166.419998   87227800   \n",
       "2022-04-22  166.460007  167.869995  161.500000  161.789993   84775200   \n",
       "2022-04-25  161.119995  163.169998  158.460007  162.880005   92824080   \n",
       "\n",
       "            Dividends  Stock Splits  \n",
       "Date                                 \n",
       "2022-03-28          0             0  \n",
       "2022-03-29          0             0  \n",
       "2022-03-30          0             0  \n",
       "2022-03-31          0             0  \n",
       "2022-04-01          0             0  \n",
       "2022-04-04          0             0  \n",
       "2022-04-05          0             0  \n",
       "2022-04-06          0             0  \n",
       "2022-04-07          0             0  \n",
       "2022-04-08          0             0  \n",
       "2022-04-11          0             0  \n",
       "2022-04-12          0             0  \n",
       "2022-04-13          0             0  \n",
       "2022-04-14          0             0  \n",
       "2022-04-18          0             0  \n",
       "2022-04-19          0             0  \n",
       "2022-04-20          0             0  \n",
       "2022-04-21          0             0  \n",
       "2022-04-22          0             0  \n",
       "2022-04-25          0             0  "
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get the last month of historical prices\n",
    "aapl_data.history()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'zip': '95014',\n",
       " 'sector': 'Technology',\n",
       " 'fullTimeEmployees': 100000,\n",
       " 'longBusinessSummary': 'Apple Inc. designs, manufactures, and markets smartphones, personal computers, tablets, wearables, and accessories worldwide. It also sells various related services. In addition, the company offers iPhone, a line of smartphones; Mac, a line of personal computers; iPad, a line of multi-purpose tablets; AirPods Max, an over-ear wireless headphone; and wearables, home, and accessories comprising AirPods, Apple TV, Apple Watch, Beats products, HomePod, and iPod touch. Further, it provides AppleCare support services; cloud services store services; and operates various platforms, including the App Store that allow customers to discover and download applications and digital content, such as books, music, video, games, and podcasts. Additionally, the company offers various services, such as Apple Arcade, a game subscription service; Apple Music, which offers users a curated listening experience with on-demand radio stations; Apple News+, a subscription news and magazine service; Apple TV+, which offers exclusive original content; Apple Card, a co-branded credit card; and Apple Pay, a cashless payment service, as well as licenses its intellectual property. The company serves consumers, and small and mid-sized businesses; and the education, enterprise, and government markets. It distributes third-party applications for its products through the App Store. The company also sells its products through its retail and online stores, and direct sales force; and third-party cellular network carriers, wholesalers, retailers, and resellers. Apple Inc. was incorporated in 1977 and is headquartered in Cupertino, California.',\n",
       " 'city': 'Cupertino',\n",
       " 'phone': '408 996 1010',\n",
       " 'state': 'CA',\n",
       " 'country': 'United States',\n",
       " 'companyOfficers': [],\n",
       " 'website': 'https://www.apple.com',\n",
       " 'maxAge': 1,\n",
       " 'address1': 'One Apple Park Way',\n",
       " 'industry': 'Consumer Electronics',\n",
       " 'ebitdaMargins': 0.33890998,\n",
       " 'profitMargins': 0.26579002,\n",
       " 'grossMargins': 0.43019,\n",
       " 'operatingCashflow': 112241000448,\n",
       " 'revenueGrowth': 0.112,\n",
       " 'operatingMargins': 0.309,\n",
       " 'ebitda': 128217997312,\n",
       " 'targetLowPrice': 160,\n",
       " 'recommendationKey': 'buy',\n",
       " 'grossProfits': 152836000000,\n",
       " 'freeCashflow': 80153247744,\n",
       " 'targetMedianPrice': 199.5,\n",
       " 'currentPrice': 162.88,\n",
       " 'earningsGrowth': 0.25,\n",
       " 'currentRatio': 1.038,\n",
       " 'returnOnAssets': 0.19875,\n",
       " 'numberOfAnalystOpinions': 44,\n",
       " 'targetMeanPrice': 193.28,\n",
       " 'debtToEquity': 170.714,\n",
       " 'returnOnEquity': 1.45567,\n",
       " 'targetHighPrice': 215,\n",
       " 'totalCash': 63913000960,\n",
       " 'totalDebt': 122797998080,\n",
       " 'totalRevenue': 378323009536,\n",
       " 'totalCashPerShare': 3.916,\n",
       " 'financialCurrency': 'USD',\n",
       " 'revenuePerShare': 22.838,\n",
       " 'quickRatio': 0.875,\n",
       " 'recommendationMean': 1.9,\n",
       " 'exchange': 'NMS',\n",
       " 'shortName': 'Apple Inc.',\n",
       " 'longName': 'Apple Inc.',\n",
       " 'exchangeTimezoneName': 'America/New_York',\n",
       " 'exchangeTimezoneShortName': 'EDT',\n",
       " 'isEsgPopulated': False,\n",
       " 'gmtOffSetMilliseconds': '-14400000',\n",
       " 'quoteType': 'EQUITY',\n",
       " 'symbol': 'AAPL',\n",
       " 'messageBoardId': 'finmb_24937',\n",
       " 'market': 'us_market',\n",
       " 'annualHoldingsTurnover': None,\n",
       " 'enterpriseToRevenue': 7.135,\n",
       " 'beta3Year': None,\n",
       " 'enterpriseToEbitda': 21.052,\n",
       " '52WeekChange': 0.20093524,\n",
       " 'morningStarRiskRating': None,\n",
       " 'forwardEps': 6.57,\n",
       " 'revenueQuarterlyGrowth': None,\n",
       " 'sharesOutstanding': 16319399936,\n",
       " 'fundInceptionDate': None,\n",
       " 'annualReportExpenseRatio': None,\n",
       " 'totalAssets': None,\n",
       " 'bookValue': 4.402,\n",
       " 'sharesShort': 101969098,\n",
       " 'sharesPercentSharesOut': 0.0062,\n",
       " 'fundFamily': None,\n",
       " 'lastFiscalYearEnd': 1632528000,\n",
       " 'heldPercentInstitutions': 0.59353,\n",
       " 'netIncomeToCommon': 100554997760,\n",
       " 'trailingEps': 6.015,\n",
       " 'lastDividendValue': 0.22,\n",
       " 'SandP52WeekChange': 0.020097375,\n",
       " 'priceToBook': 37.001366,\n",
       " 'heldPercentInsiders': 0.00071000005,\n",
       " 'nextFiscalYearEnd': 1695600000,\n",
       " 'yield': None,\n",
       " 'mostRecentQuarter': 1640390400,\n",
       " 'shortRatio': 1.08,\n",
       " 'sharesShortPreviousMonthDate': 1646006400,\n",
       " 'floatShares': 16302631976,\n",
       " 'beta': 1.187745,\n",
       " 'enterpriseValue': 2699207376896,\n",
       " 'priceHint': 2,\n",
       " 'threeYearAverageReturn': None,\n",
       " 'lastSplitDate': 1598832000,\n",
       " 'lastSplitFactor': '4:1',\n",
       " 'legalType': None,\n",
       " 'lastDividendDate': 1643932800,\n",
       " 'morningStarOverallRating': None,\n",
       " 'earningsQuarterlyGrowth': 0.204,\n",
       " 'priceToSalesTrailing12Months': 7.026017,\n",
       " 'dateShortInterest': 1648684800,\n",
       " 'pegRatio': 2.62,\n",
       " 'ytdReturn': None,\n",
       " 'forwardPE': 24.791477,\n",
       " 'lastCapGain': None,\n",
       " 'shortPercentOfFloat': 0.0063,\n",
       " 'sharesShortPriorMonth': 110322490,\n",
       " 'impliedSharesOutstanding': 0,\n",
       " 'category': None,\n",
       " 'fiveYearAverageReturn': None,\n",
       " 'previousClose': 161.79,\n",
       " 'regularMarketOpen': 161.12,\n",
       " 'twoHundredDayAverage': 158.973,\n",
       " 'trailingAnnualDividendYield': 0.005346437,\n",
       " 'payoutRatio': 0.1434,\n",
       " 'volume24Hr': None,\n",
       " 'regularMarketDayHigh': 163.17,\n",
       " 'navPrice': None,\n",
       " 'averageDailyVolume10Day': 75056470,\n",
       " 'regularMarketPreviousClose': 161.79,\n",
       " 'fiftyDayAverage': 166.9856,\n",
       " 'trailingAnnualDividendRate': 0.865,\n",
       " 'open': 161.12,\n",
       " 'toCurrency': None,\n",
       " 'averageVolume10days': 75056470,\n",
       " 'expireDate': None,\n",
       " 'algorithm': None,\n",
       " 'dividendRate': 0.88,\n",
       " 'exDividendDate': 1643932800,\n",
       " 'circulatingSupply': None,\n",
       " 'startDate': None,\n",
       " 'regularMarketDayLow': 158.46,\n",
       " 'currency': 'USD',\n",
       " 'trailingPE': 27.07897,\n",
       " 'regularMarketVolume': 92824080,\n",
       " 'lastMarket': None,\n",
       " 'maxSupply': None,\n",
       " 'openInterest': None,\n",
       " 'marketCap': 2658103984128,\n",
       " 'volumeAllCurrencies': None,\n",
       " 'strikePrice': None,\n",
       " 'averageVolume': 89832980,\n",
       " 'dayLow': 158.46,\n",
       " 'ask': 163.13,\n",
       " 'askSize': 900,\n",
       " 'volume': 92824080,\n",
       " 'fiftyTwoWeekHigh': 182.94,\n",
       " 'fromCurrency': None,\n",
       " 'fiveYearAvgDividendYield': 1.11,\n",
       " 'fiftyTwoWeekLow': 122.25,\n",
       " 'bid': 163.1,\n",
       " 'tradeable': False,\n",
       " 'dividendYield': 0.0054,\n",
       " 'bidSize': 900,\n",
       " 'dayHigh': 163.17,\n",
       " 'regularMarketPrice': 162.88,\n",
       " 'preMarketPrice': 161.18,\n",
       " 'logo_url': 'https://logo.clearbit.com/apple.com',\n",
       " 'trailingPegRatio': 3.1111}"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get stock's info\n",
    "aapl_data.info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [Dividends, Stock Splits]\n",
       "Index: []"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show corporate actions\n",
    "aapl_data.actions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2021-09-25</th>\n",
       "      <th>2020-09-26</th>\n",
       "      <th>2019-09-28</th>\n",
       "      <th>2018-09-29</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Research Development</th>\n",
       "      <td>21914000000.0</td>\n",
       "      <td>18752000000.0</td>\n",
       "      <td>16217000000.0</td>\n",
       "      <td>14236000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Effect Of Accounting Charges</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Income Before Tax</th>\n",
       "      <td>109207000000.0</td>\n",
       "      <td>67091000000.0</td>\n",
       "      <td>65737000000.0</td>\n",
       "      <td>72903000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Minority Interest</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Net Income</th>\n",
       "      <td>94680000000.0</td>\n",
       "      <td>57411000000.0</td>\n",
       "      <td>55256000000.0</td>\n",
       "      <td>59531000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Selling General Administrative</th>\n",
       "      <td>21973000000.0</td>\n",
       "      <td>19916000000.0</td>\n",
       "      <td>18245000000.0</td>\n",
       "      <td>16705000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gross Profit</th>\n",
       "      <td>152836000000.0</td>\n",
       "      <td>104956000000.0</td>\n",
       "      <td>98392000000.0</td>\n",
       "      <td>101839000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ebit</th>\n",
       "      <td>108949000000.0</td>\n",
       "      <td>66288000000.0</td>\n",
       "      <td>63930000000.0</td>\n",
       "      <td>70898000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Operating Income</th>\n",
       "      <td>108949000000.0</td>\n",
       "      <td>66288000000.0</td>\n",
       "      <td>63930000000.0</td>\n",
       "      <td>70898000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Other Operating Expenses</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Interest Expense</th>\n",
       "      <td>-2645000000.0</td>\n",
       "      <td>-2873000000.0</td>\n",
       "      <td>-3576000000.0</td>\n",
       "      <td>-3240000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Extraordinary Items</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Non Recurring</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Other Items</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Income Tax Expense</th>\n",
       "      <td>14527000000.0</td>\n",
       "      <td>9680000000.0</td>\n",
       "      <td>10481000000.0</td>\n",
       "      <td>13372000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Total Revenue</th>\n",
       "      <td>365817000000.0</td>\n",
       "      <td>274515000000.0</td>\n",
       "      <td>260174000000.0</td>\n",
       "      <td>265595000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Total Operating Expenses</th>\n",
       "      <td>256868000000.0</td>\n",
       "      <td>208227000000.0</td>\n",
       "      <td>196244000000.0</td>\n",
       "      <td>194697000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cost Of Revenue</th>\n",
       "      <td>212981000000.0</td>\n",
       "      <td>169559000000.0</td>\n",
       "      <td>161782000000.0</td>\n",
       "      <td>163756000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Total Other Income Expense Net</th>\n",
       "      <td>258000000.0</td>\n",
       "      <td>803000000.0</td>\n",
       "      <td>1807000000.0</td>\n",
       "      <td>2005000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Discontinued Operations</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Net Income From Continuing Ops</th>\n",
       "      <td>94680000000.0</td>\n",
       "      <td>57411000000.0</td>\n",
       "      <td>55256000000.0</td>\n",
       "      <td>59531000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Net Income Applicable To Common Shares</th>\n",
       "      <td>94680000000.0</td>\n",
       "      <td>57411000000.0</td>\n",
       "      <td>55256000000.0</td>\n",
       "      <td>59531000000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            2021-09-25      2020-09-26  \\\n",
       "Research Development                     21914000000.0   18752000000.0   \n",
       "Effect Of Accounting Charges                      None            None   \n",
       "Income Before Tax                       109207000000.0   67091000000.0   \n",
       "Minority Interest                                 None            None   \n",
       "Net Income                               94680000000.0   57411000000.0   \n",
       "Selling General Administrative           21973000000.0   19916000000.0   \n",
       "Gross Profit                            152836000000.0  104956000000.0   \n",
       "Ebit                                    108949000000.0   66288000000.0   \n",
       "Operating Income                        108949000000.0   66288000000.0   \n",
       "Other Operating Expenses                          None            None   \n",
       "Interest Expense                         -2645000000.0   -2873000000.0   \n",
       "Extraordinary Items                               None            None   \n",
       "Non Recurring                                     None            None   \n",
       "Other Items                                       None            None   \n",
       "Income Tax Expense                       14527000000.0    9680000000.0   \n",
       "Total Revenue                           365817000000.0  274515000000.0   \n",
       "Total Operating Expenses                256868000000.0  208227000000.0   \n",
       "Cost Of Revenue                         212981000000.0  169559000000.0   \n",
       "Total Other Income Expense Net             258000000.0     803000000.0   \n",
       "Discontinued Operations                           None            None   \n",
       "Net Income From Continuing Ops           94680000000.0   57411000000.0   \n",
       "Net Income Applicable To Common Shares   94680000000.0   57411000000.0   \n",
       "\n",
       "                                            2019-09-28      2018-09-29  \n",
       "Research Development                     16217000000.0   14236000000.0  \n",
       "Effect Of Accounting Charges                      None            None  \n",
       "Income Before Tax                        65737000000.0   72903000000.0  \n",
       "Minority Interest                                 None            None  \n",
       "Net Income                               55256000000.0   59531000000.0  \n",
       "Selling General Administrative           18245000000.0   16705000000.0  \n",
       "Gross Profit                             98392000000.0  101839000000.0  \n",
       "Ebit                                     63930000000.0   70898000000.0  \n",
       "Operating Income                         63930000000.0   70898000000.0  \n",
       "Other Operating Expenses                          None            None  \n",
       "Interest Expense                         -3576000000.0   -3240000000.0  \n",
       "Extraordinary Items                               None            None  \n",
       "Non Recurring                                     None            None  \n",
       "Other Items                                       None            None  \n",
       "Income Tax Expense                       10481000000.0   13372000000.0  \n",
       "Total Revenue                           260174000000.0  265595000000.0  \n",
       "Total Operating Expenses                196244000000.0  194697000000.0  \n",
       "Cost Of Revenue                         161782000000.0  163756000000.0  \n",
       "Total Other Income Expense Net            1807000000.0    2005000000.0  \n",
       "Discontinued Operations                           None            None  \n",
       "Net Income From Continuing Ops           55256000000.0   59531000000.0  \n",
       "Net Income Applicable To Common Shares   55256000000.0   59531000000.0  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show financials\n",
    "aapl_data.financials"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2021-12-25</th>\n",
       "      <th>2021-09-25</th>\n",
       "      <th>2021-06-26</th>\n",
       "      <th>2021-03-27</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Research Development</th>\n",
       "      <td>6306000000.0</td>\n",
       "      <td>5772000000.0</td>\n",
       "      <td>5717000000.0</td>\n",
       "      <td>5262000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Effect Of Accounting Charges</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Income Before Tax</th>\n",
       "      <td>41241000000.0</td>\n",
       "      <td>23248000000.0</td>\n",
       "      <td>24369000000.0</td>\n",
       "      <td>28011000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Minority Interest</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Net Income</th>\n",
       "      <td>34630000000.0</td>\n",
       "      <td>20551000000.0</td>\n",
       "      <td>21744000000.0</td>\n",
       "      <td>23630000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Selling General Administrative</th>\n",
       "      <td>6449000000.0</td>\n",
       "      <td>5616000000.0</td>\n",
       "      <td>5412000000.0</td>\n",
       "      <td>5314000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gross Profit</th>\n",
       "      <td>54243000000.0</td>\n",
       "      <td>35174000000.0</td>\n",
       "      <td>35255000000.0</td>\n",
       "      <td>38079000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ebit</th>\n",
       "      <td>41488000000.0</td>\n",
       "      <td>23786000000.0</td>\n",
       "      <td>24126000000.0</td>\n",
       "      <td>27503000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Operating Income</th>\n",
       "      <td>41488000000.0</td>\n",
       "      <td>23786000000.0</td>\n",
       "      <td>24126000000.0</td>\n",
       "      <td>27503000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Other Operating Expenses</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Interest Expense</th>\n",
       "      <td>-694000000.0</td>\n",
       "      <td>-672000000.0</td>\n",
       "      <td>-665000000.0</td>\n",
       "      <td>-670000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Extraordinary Items</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Non Recurring</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Other Items</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Income Tax Expense</th>\n",
       "      <td>6611000000.0</td>\n",
       "      <td>2697000000.0</td>\n",
       "      <td>2625000000.0</td>\n",
       "      <td>4381000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Total Revenue</th>\n",
       "      <td>123945000000.0</td>\n",
       "      <td>83360000000.0</td>\n",
       "      <td>81434000000.0</td>\n",
       "      <td>89584000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Total Operating Expenses</th>\n",
       "      <td>82457000000.0</td>\n",
       "      <td>59574000000.0</td>\n",
       "      <td>57308000000.0</td>\n",
       "      <td>62081000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cost Of Revenue</th>\n",
       "      <td>69702000000.0</td>\n",
       "      <td>48186000000.0</td>\n",
       "      <td>46179000000.0</td>\n",
       "      <td>51505000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Total Other Income Expense Net</th>\n",
       "      <td>-247000000.0</td>\n",
       "      <td>-538000000.0</td>\n",
       "      <td>243000000.0</td>\n",
       "      <td>508000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Discontinued Operations</th>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Net Income From Continuing Ops</th>\n",
       "      <td>34630000000.0</td>\n",
       "      <td>20551000000.0</td>\n",
       "      <td>21744000000.0</td>\n",
       "      <td>23630000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Net Income Applicable To Common Shares</th>\n",
       "      <td>34630000000.0</td>\n",
       "      <td>20551000000.0</td>\n",
       "      <td>21744000000.0</td>\n",
       "      <td>23630000000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            2021-12-25     2021-09-25  \\\n",
       "Research Development                      6306000000.0   5772000000.0   \n",
       "Effect Of Accounting Charges                      None           None   \n",
       "Income Before Tax                        41241000000.0  23248000000.0   \n",
       "Minority Interest                                 None           None   \n",
       "Net Income                               34630000000.0  20551000000.0   \n",
       "Selling General Administrative            6449000000.0   5616000000.0   \n",
       "Gross Profit                             54243000000.0  35174000000.0   \n",
       "Ebit                                     41488000000.0  23786000000.0   \n",
       "Operating Income                         41488000000.0  23786000000.0   \n",
       "Other Operating Expenses                          None           None   \n",
       "Interest Expense                          -694000000.0   -672000000.0   \n",
       "Extraordinary Items                               None           None   \n",
       "Non Recurring                                     None           None   \n",
       "Other Items                                       None           None   \n",
       "Income Tax Expense                        6611000000.0   2697000000.0   \n",
       "Total Revenue                           123945000000.0  83360000000.0   \n",
       "Total Operating Expenses                 82457000000.0  59574000000.0   \n",
       "Cost Of Revenue                          69702000000.0  48186000000.0   \n",
       "Total Other Income Expense Net            -247000000.0   -538000000.0   \n",
       "Discontinued Operations                           None           None   \n",
       "Net Income From Continuing Ops           34630000000.0  20551000000.0   \n",
       "Net Income Applicable To Common Shares   34630000000.0  20551000000.0   \n",
       "\n",
       "                                           2021-06-26     2021-03-27  \n",
       "Research Development                     5717000000.0   5262000000.0  \n",
       "Effect Of Accounting Charges                     None           None  \n",
       "Income Before Tax                       24369000000.0  28011000000.0  \n",
       "Minority Interest                                None           None  \n",
       "Net Income                              21744000000.0  23630000000.0  \n",
       "Selling General Administrative           5412000000.0   5314000000.0  \n",
       "Gross Profit                            35255000000.0  38079000000.0  \n",
       "Ebit                                    24126000000.0  27503000000.0  \n",
       "Operating Income                        24126000000.0  27503000000.0  \n",
       "Other Operating Expenses                         None           None  \n",
       "Interest Expense                         -665000000.0   -670000000.0  \n",
       "Extraordinary Items                              None           None  \n",
       "Non Recurring                                    None           None  \n",
       "Other Items                                      None           None  \n",
       "Income Tax Expense                       2625000000.0   4381000000.0  \n",
       "Total Revenue                           81434000000.0  89584000000.0  \n",
       "Total Operating Expenses                57308000000.0  62081000000.0  \n",
       "Cost Of Revenue                         46179000000.0  51505000000.0  \n",
       "Total Other Income Expense Net            243000000.0    508000000.0  \n",
       "Discontinued Operations                          None           None  \n",
       "Net Income From Continuing Ops          21744000000.0  23630000000.0  \n",
       "Net Income Applicable To Common Shares  21744000000.0  23630000000.0  "
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show quarterly financials\n",
    "aapl_data.quarterly_financials"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Revenue</th>\n",
       "      <th>Earnings</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Year</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018</th>\n",
       "      <td>265595000000</td>\n",
       "      <td>59531000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019</th>\n",
       "      <td>260174000000</td>\n",
       "      <td>55256000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020</th>\n",
       "      <td>274515000000</td>\n",
       "      <td>57411000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021</th>\n",
       "      <td>365817000000</td>\n",
       "      <td>94680000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Revenue     Earnings\n",
       "Year                           \n",
       "2018  265595000000  59531000000\n",
       "2019  260174000000  55256000000\n",
       "2020  274515000000  57411000000\n",
       "2021  365817000000  94680000000"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show earnings\n",
    "aapl_data.earnings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Revenue</th>\n",
       "      <th>Earnings</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Quarter</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1Q2021</th>\n",
       "      <td>89584000000</td>\n",
       "      <td>23630000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2Q2021</th>\n",
       "      <td>81434000000</td>\n",
       "      <td>21744000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3Q2021</th>\n",
       "      <td>83360000000</td>\n",
       "      <td>20551000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4Q2021</th>\n",
       "      <td>123945000000</td>\n",
       "      <td>34630000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Revenue     Earnings\n",
       "Quarter                           \n",
       "1Q2021    89584000000  23630000000\n",
       "2Q2021    81434000000  21744000000\n",
       "3Q2021    83360000000  20551000000\n",
       "4Q2021   123945000000  34630000000"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show quarterly earnings\n",
    "aapl_data.quarterly_earnings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Earnings Date</th>\n",
       "      <td>2022-04-28 20:00:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Earnings Average</th>\n",
       "      <td>1.43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Earnings Low</th>\n",
       "      <td>1.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Earnings High</th>\n",
       "      <td>1.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Revenue Average</th>\n",
       "      <td>94024200000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Revenue Low</th>\n",
       "      <td>90042000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Revenue High</th>\n",
       "      <td>100444000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                Value\n",
       "Earnings Date     2022-04-28 20:00:00\n",
       "Earnings Average                 1.43\n",
       "Earnings Low                     1.34\n",
       "Earnings High                    1.56\n",
       "Revenue Average           94024200000\n",
       "Revenue Low               90042000000\n",
       "Revenue High             100444000000"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# show upcoming events, such as earnings\n",
    "aapl_data.calendar"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.2 Getting data from Nasdaq Data Link "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Import the libraries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-17T23:30:43.327777Z",
     "start_time": "2020-01-17T23:30:43.293840Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import nasdaqdatalink"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Authenticate using the personal API key:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-25T18:11:14.299274Z",
     "start_time": "2019-11-25T18:11:14.296279Z"
    }
   },
   "outputs": [],
   "source": [
    "nasdaqdatalink.ApiConfig.api_key = \"YOUR_KEY_HERE\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Download the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-25T18:03:25.212313Z",
     "start_time": "2019-11-25T18:03:22.971743Z"
    }
   },
   "outputs": [],
   "source": [
    "df = nasdaqdatalink.get(dataset=\"WIKI/AAPL\",\n",
    "                        start_date=\"2011-01-01\", \n",
    "                        end_date=\"2021-12-31\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. Inspect the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-11-25T18:03:25.713899Z",
     "start_time": "2019-11-25T18:03:25.695790Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloaded 1818 rows of data.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Ex-Dividend</th>\n",
       "      <th>Split Ratio</th>\n",
       "      <th>Adj. Open</th>\n",
       "      <th>Adj. High</th>\n",
       "      <th>Adj. Low</th>\n",
       "      <th>Adj. Close</th>\n",
       "      <th>Adj. Volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2011-01-03</th>\n",
       "      <td>325.6400</td>\n",
       "      <td>330.26</td>\n",
       "      <td>324.8365</td>\n",
       "      <td>329.57</td>\n",
       "      <td>15897800.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>41.849279</td>\n",
       "      <td>42.443013</td>\n",
       "      <td>41.746018</td>\n",
       "      <td>42.354338</td>\n",
       "      <td>111284600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-04</th>\n",
       "      <td>332.4400</td>\n",
       "      <td>332.50</td>\n",
       "      <td>328.1500</td>\n",
       "      <td>331.29</td>\n",
       "      <td>11038600.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>42.723173</td>\n",
       "      <td>42.730884</td>\n",
       "      <td>42.171849</td>\n",
       "      <td>42.575382</td>\n",
       "      <td>77270200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-05</th>\n",
       "      <td>329.5500</td>\n",
       "      <td>334.34</td>\n",
       "      <td>329.5000</td>\n",
       "      <td>334.00</td>\n",
       "      <td>9125700.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>42.351768</td>\n",
       "      <td>42.967350</td>\n",
       "      <td>42.345342</td>\n",
       "      <td>42.923655</td>\n",
       "      <td>63879900.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-06</th>\n",
       "      <td>334.7194</td>\n",
       "      <td>335.25</td>\n",
       "      <td>332.9000</td>\n",
       "      <td>333.73</td>\n",
       "      <td>10729600.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>43.016108</td>\n",
       "      <td>43.084298</td>\n",
       "      <td>42.782290</td>\n",
       "      <td>42.888956</td>\n",
       "      <td>75107200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-07</th>\n",
       "      <td>333.9900</td>\n",
       "      <td>336.35</td>\n",
       "      <td>331.9000</td>\n",
       "      <td>336.12</td>\n",
       "      <td>11140400.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>42.922370</td>\n",
       "      <td>43.225663</td>\n",
       "      <td>42.653776</td>\n",
       "      <td>43.196105</td>\n",
       "      <td>77982800.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Open    High       Low   Close      Volume  Ex-Dividend  \\\n",
       "Date                                                                      \n",
       "2011-01-03  325.6400  330.26  324.8365  329.57  15897800.0          0.0   \n",
       "2011-01-04  332.4400  332.50  328.1500  331.29  11038600.0          0.0   \n",
       "2011-01-05  329.5500  334.34  329.5000  334.00   9125700.0          0.0   \n",
       "2011-01-06  334.7194  335.25  332.9000  333.73  10729600.0          0.0   \n",
       "2011-01-07  333.9900  336.35  331.9000  336.12  11140400.0          0.0   \n",
       "\n",
       "            Split Ratio  Adj. Open  Adj. High   Adj. Low  Adj. Close  \\\n",
       "Date                                                                   \n",
       "2011-01-03          1.0  41.849279  42.443013  41.746018   42.354338   \n",
       "2011-01-04          1.0  42.723173  42.730884  42.171849   42.575382   \n",
       "2011-01-05          1.0  42.351768  42.967350  42.345342   42.923655   \n",
       "2011-01-06          1.0  43.016108  43.084298  42.782290   42.888956   \n",
       "2011-01-07          1.0  42.922370  43.225663  42.653776   43.196105   \n",
       "\n",
       "            Adj. Volume  \n",
       "Date                     \n",
       "2011-01-03  111284600.0  \n",
       "2011-01-04   77270200.0  \n",
       "2011-01-05   63879900.0  \n",
       "2011-01-06   75107200.0  \n",
       "2011-01-07   77982800.0  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(f\"Downloaded {len(df)} rows of data.\")\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Download the data for multiple tickers using the `get_table` function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>date</th>\n",
       "      <th>adj_close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>None</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>2018-03-27</td>\n",
       "      <td>89.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>2018-03-26</td>\n",
       "      <td>93.78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>2018-03-23</td>\n",
       "      <td>87.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>2018-03-22</td>\n",
       "      <td>89.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>2018-03-21</td>\n",
       "      <td>92.48</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ticker       date  adj_close\n",
       "None                             \n",
       "0      MSFT 2018-03-27      89.47\n",
       "1      MSFT 2018-03-26      93.78\n",
       "2      MSFT 2018-03-23      87.18\n",
       "3      MSFT 2018-03-22      89.79\n",
       "4      MSFT 2018-03-21      92.48"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "COLUMNS = [\"ticker\", \"date\", \"adj_close\"]\n",
    "df = nasdaqdatalink.get_table(\"WIKI/PRICES\", \n",
    "                              ticker=[\"AAPL\", \"MSFT\", \"INTC\"], \n",
    "                              qopts={\"columns\": COLUMNS}, \n",
    "                              date={\"gte\": \"2011-01-01\", \n",
    "                                    \"lte\": \"2021-12-31\"}, \n",
    "                              paginate=True)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Pivot the data from long to wide:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">adj_close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ticker</th>\n",
       "      <th>AAPL</th>\n",
       "      <th>INTC</th>\n",
       "      <th>MSFT</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2011-01-03</th>\n",
       "      <td>42.354338</td>\n",
       "      <td>16.488706</td>\n",
       "      <td>23.211568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-04</th>\n",
       "      <td>42.575382</td>\n",
       "      <td>16.725954</td>\n",
       "      <td>23.300747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-05</th>\n",
       "      <td>42.923655</td>\n",
       "      <td>16.559880</td>\n",
       "      <td>23.228159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-06</th>\n",
       "      <td>42.888956</td>\n",
       "      <td>16.425440</td>\n",
       "      <td>23.908412</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-07</th>\n",
       "      <td>43.196105</td>\n",
       "      <td>16.338449</td>\n",
       "      <td>23.725905</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            adj_close                      \n",
       "ticker           AAPL       INTC       MSFT\n",
       "date                                       \n",
       "2011-01-03  42.354338  16.488706  23.211568\n",
       "2011-01-04  42.575382  16.725954  23.300747\n",
       "2011-01-05  42.923655  16.559880  23.228159\n",
       "2011-01-06  42.888956  16.425440  23.908412\n",
       "2011-01-07  43.196105  16.338449  23.725905"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# set the date as index\n",
    "df = df.set_index(\"date\")\n",
    "\n",
    "# use the pivot function to reshape the data\n",
    "df_wide = df.pivot(columns=\"ticker\")\n",
    "df_wide.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.3 Getting data from Intrinio"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Import the libraries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-18T13:01:52.376042Z",
     "start_time": "2020-01-18T13:01:52.017561Z"
    }
   },
   "outputs": [],
   "source": [
    "import intrinio_sdk as intrinio\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Authenticate using the personal API key and select the API:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-18T13:01:53.751757Z",
     "start_time": "2020-01-18T13:01:53.720336Z"
    }
   },
   "outputs": [],
   "source": [
    "intrinio.ApiClient().set_api_key(\"YOUR_KEY_HERE\") \n",
    "security_api = intrinio.SecurityApi()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Request the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-18T13:01:56.623594Z",
     "start_time": "2020-01-18T13:01:54.658274Z"
    }
   },
   "outputs": [],
   "source": [
    "r = security_api.get_security_stock_prices(\n",
    "    identifier=\"AAPL\", \n",
    "    start_date=\"2011-01-01\",\n",
    "    end_date=\"2021-12-31\", \n",
    "    frequency=\"daily\",\n",
    "    page_size=10000\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. Convert the results into a DataFrame:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-18T13:02:00.998268Z",
     "start_time": "2020-01-18T13:02:00.968257Z"
    }
   },
   "outputs": [],
   "source": [
    "df = (\n",
    "    pd.DataFrame(r.stock_prices_dict)\n",
    "    .sort_values(\"date\")\n",
    "    .set_index(\"date\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5. Inspect the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-01-18T13:02:04.423570Z",
     "start_time": "2020-01-18T13:02:04.409498Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloaded 2675 rows of data.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>intraperiod</th>\n",
       "      <th>frequency</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>volume</th>\n",
       "      <th>adj_open</th>\n",
       "      <th>adj_high</th>\n",
       "      <th>adj_low</th>\n",
       "      <th>adj_close</th>\n",
       "      <th>adj_volume</th>\n",
       "      <th>factor</th>\n",
       "      <th>split_ratio</th>\n",
       "      <th>dividend</th>\n",
       "      <th>change</th>\n",
       "      <th>percent_change</th>\n",
       "      <th>fifty_two_week_high</th>\n",
       "      <th>fifty_two_week_low</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2011-01-03</th>\n",
       "      <td>False</td>\n",
       "      <td>daily</td>\n",
       "      <td>325.90</td>\n",
       "      <td>330.26</td>\n",
       "      <td>324.8365</td>\n",
       "      <td>329.57</td>\n",
       "      <td>15897201.0</td>\n",
       "      <td>9.993683</td>\n",
       "      <td>10.127381</td>\n",
       "      <td>9.961070</td>\n",
       "      <td>10.106223</td>\n",
       "      <td>445121628.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.21</td>\n",
       "      <td>0.0217</td>\n",
       "      <td>10.13</td>\n",
       "      <td>5.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-04</th>\n",
       "      <td>False</td>\n",
       "      <td>daily</td>\n",
       "      <td>332.50</td>\n",
       "      <td>332.50</td>\n",
       "      <td>328.1500</td>\n",
       "      <td>331.29</td>\n",
       "      <td>11048143.0</td>\n",
       "      <td>10.196071</td>\n",
       "      <td>10.196071</td>\n",
       "      <td>10.062679</td>\n",
       "      <td>10.158966</td>\n",
       "      <td>309348004.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.0052</td>\n",
       "      <td>10.20</td>\n",
       "      <td>5.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-05</th>\n",
       "      <td>False</td>\n",
       "      <td>daily</td>\n",
       "      <td>329.55</td>\n",
       "      <td>334.34</td>\n",
       "      <td>329.5000</td>\n",
       "      <td>334.00</td>\n",
       "      <td>9125599.0</td>\n",
       "      <td>10.105609</td>\n",
       "      <td>10.252494</td>\n",
       "      <td>10.104076</td>\n",
       "      <td>10.242068</td>\n",
       "      <td>255516772.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.08</td>\n",
       "      <td>0.0082</td>\n",
       "      <td>10.25</td>\n",
       "      <td>5.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-06</th>\n",
       "      <td>False</td>\n",
       "      <td>daily</td>\n",
       "      <td>335.00</td>\n",
       "      <td>335.25</td>\n",
       "      <td>332.9000</td>\n",
       "      <td>333.73</td>\n",
       "      <td>10729518.0</td>\n",
       "      <td>10.272733</td>\n",
       "      <td>10.280399</td>\n",
       "      <td>10.208337</td>\n",
       "      <td>10.233789</td>\n",
       "      <td>300426504.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>-0.0008</td>\n",
       "      <td>10.28</td>\n",
       "      <td>5.83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-01-07</th>\n",
       "      <td>False</td>\n",
       "      <td>daily</td>\n",
       "      <td>334.12</td>\n",
       "      <td>336.35</td>\n",
       "      <td>331.9000</td>\n",
       "      <td>336.12</td>\n",
       "      <td>11140316.0</td>\n",
       "      <td>10.245748</td>\n",
       "      <td>10.314130</td>\n",
       "      <td>10.177672</td>\n",
       "      <td>10.307078</td>\n",
       "      <td>311928848.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.07</td>\n",
       "      <td>0.0072</td>\n",
       "      <td>10.31</td>\n",
       "      <td>5.83</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            intraperiod frequency    open    high       low   close  \\\n",
       "date                                                                  \n",
       "2011-01-03        False     daily  325.90  330.26  324.8365  329.57   \n",
       "2011-01-04        False     daily  332.50  332.50  328.1500  331.29   \n",
       "2011-01-05        False     daily  329.55  334.34  329.5000  334.00   \n",
       "2011-01-06        False     daily  335.00  335.25  332.9000  333.73   \n",
       "2011-01-07        False     daily  334.12  336.35  331.9000  336.12   \n",
       "\n",
       "                volume   adj_open   adj_high    adj_low  adj_close  \\\n",
       "date                                                                 \n",
       "2011-01-03  15897201.0   9.993683  10.127381   9.961070  10.106223   \n",
       "2011-01-04  11048143.0  10.196071  10.196071  10.062679  10.158966   \n",
       "2011-01-05   9125599.0  10.105609  10.252494  10.104076  10.242068   \n",
       "2011-01-06  10729518.0  10.272733  10.280399  10.208337  10.233789   \n",
       "2011-01-07  11140316.0  10.245748  10.314130  10.177672  10.307078   \n",
       "\n",
       "             adj_volume  factor  split_ratio  dividend  change  \\\n",
       "date                                                             \n",
       "2011-01-03  445121628.0     1.0          1.0       0.0    0.21   \n",
       "2011-01-04  309348004.0     1.0          1.0       0.0    0.05   \n",
       "2011-01-05  255516772.0     1.0          1.0       0.0    0.08   \n",
       "2011-01-06  300426504.0     1.0          1.0       0.0   -0.01   \n",
       "2011-01-07  311928848.0     1.0          1.0       0.0    0.07   \n",
       "\n",
       "            percent_change  fifty_two_week_high  fifty_two_week_low  \n",
       "date                                                                 \n",
       "2011-01-03          0.0217                10.13                5.83  \n",
       "2011-01-04          0.0052                10.20                5.83  \n",
       "2011-01-05          0.0082                10.25                5.83  \n",
       "2011-01-06         -0.0008                10.28                5.83  \n",
       "2011-01-07          0.0072                10.31                5.83  "
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(f\"Downloaded {df.shape[0]} rows of data.\")\n",
    "\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Get Coca-Cola's real-time stock price:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'ask_price': 68.0,\n",
       " 'ask_size': 1.0,\n",
       " 'bid_price': 64.0,\n",
       " 'bid_size': 1.0,\n",
       " 'close_price': None,\n",
       " 'exchange_volume': 1527525.0,\n",
       " 'high_price': 67.03,\n",
       " 'last_price': 66.1,\n",
       " 'last_size': None,\n",
       " 'last_time': datetime.datetime(2022, 4, 25, 22, 6, 17, tzinfo=tzutc()),\n",
       " 'low_price': 48.13,\n",
       " 'market_volume': None,\n",
       " 'open_price': 66.5,\n",
       " 'security': {'composite_figi': 'BBG000BMX289',\n",
       "              'exchange_ticker': 'KO:UN',\n",
       "              'figi': 'BBG000BMX4N8',\n",
       "              'id': 'sec_X7m9Zy',\n",
       "              'ticker': 'KO'},\n",
       " 'source': 'bats_delayed',\n",
       " 'updated_on': datetime.datetime(2022, 4, 25, 22, 21, 20, 659000, tzinfo=tzutc())}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "security_api.get_security_realtime_price(\"KO\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Download news articles related to Coca-Cola:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "tags": [
     "outputPrepend"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>publication_date</th>\n",
       "      <th>url</th>\n",
       "      <th>summary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>nws_1ExBnx</td>\n",
       "      <td>12 Best Blue-Chip Stocks Right Now</td>\n",
       "      <td>2021-08-09 20:27:39+00:00</td>\n",
       "      <td>https://finance.yahoo.com/news/12-best-blue-ch...</td>\n",
       "      <td>In this article, we will look at the 12 best b...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>nws_JbL8mV</td>\n",
       "      <td>The Coca-Cola Company (NYSE:KO) Yields 3% With...</td>\n",
       "      <td>2021-08-09 09:26:07+00:00</td>\n",
       "      <td>https://finance.yahoo.com/news/coca-cola-compa...</td>\n",
       "      <td>The Coca-Cola Company NYSE:KO) is a staple sto...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>nws_DkAPKO</td>\n",
       "      <td>10 High Yield Monthly Dividend Stocks to Buy i...</td>\n",
       "      <td>2021-08-07 13:57:00+00:00</td>\n",
       "      <td>https://finance.yahoo.com/news/10-high-yield-m...</td>\n",
       "      <td>In this article, we will be looking at 10 high...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>nws_pRYkD9</td>\n",
       "      <td>10 Best Dividend Paying Stocks to Buy Now</td>\n",
       "      <td>2021-08-04 14:32:49+00:00</td>\n",
       "      <td>https://finance.yahoo.com/news/10-best-dividen...</td>\n",
       "      <td>In this article, we will be looking at the 10 ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>nws_kpVJDP</td>\n",
       "      <td>PepsiCo (PEP) Agrees to Offload Its Juice Bran...</td>\n",
       "      <td>2021-08-04 13:21:01+00:00</td>\n",
       "      <td>https://finance.yahoo.com/news/pepsico-pep-agr...</td>\n",
       "      <td>PepsiCo (PEP) unveils plans to offload juice b...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           id                                              title  \\\n",
       "0  nws_1ExBnx                 12 Best Blue-Chip Stocks Right Now   \n",
       "1  nws_JbL8mV  The Coca-Cola Company (NYSE:KO) Yields 3% With...   \n",
       "2  nws_DkAPKO  10 High Yield Monthly Dividend Stocks to Buy i...   \n",
       "3  nws_pRYkD9          10 Best Dividend Paying Stocks to Buy Now   \n",
       "4  nws_kpVJDP  PepsiCo (PEP) Agrees to Offload Its Juice Bran...   \n",
       "\n",
       "           publication_date  \\\n",
       "0 2021-08-09 20:27:39+00:00   \n",
       "1 2021-08-09 09:26:07+00:00   \n",
       "2 2021-08-07 13:57:00+00:00   \n",
       "3 2021-08-04 14:32:49+00:00   \n",
       "4 2021-08-04 13:21:01+00:00   \n",
       "\n",
       "                                                 url  \\\n",
       "0  https://finance.yahoo.com/news/12-best-blue-ch...   \n",
       "1  https://finance.yahoo.com/news/coca-cola-compa...   \n",
       "2  https://finance.yahoo.com/news/10-high-yield-m...   \n",
       "3  https://finance.yahoo.com/news/10-best-dividen...   \n",
       "4  https://finance.yahoo.com/news/pepsico-pep-agr...   \n",
       "\n",
       "                                             summary  \n",
       "0  In this article, we will look at the 12 best b...  \n",
       "1  The Coca-Cola Company NYSE:KO) is a staple sto...  \n",
       "2  In this article, we will be looking at 10 high...  \n",
       "3  In this article, we will be looking at the 10 ...  \n",
       "4  PepsiCo (PEP) unveils plans to offload juice b...  "
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = intrinio.CompanyApi().get_company_news(\n",
    "    identifier=\"KO\", \n",
    "    page_size=100\n",
    ")\n",
    "\n",
    "df = pd.DataFrame(r.news_dict)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Search for companies connected to the search phrase:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Returns a list of companies recognized by the Thea API in the given `text` query string parameter. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = intrinio.CompanyApi().recognize_company(\"Intel\")\n",
    "df = pd.DataFrame(r.companies_dict)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. Get Coca-Cola's intraday stock prices:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>last_price</th>\n",
       "      <th>ask_price</th>\n",
       "      <th>ask_size</th>\n",
       "      <th>bid_price</th>\n",
       "      <th>bid_size</th>\n",
       "      <th>volume</th>\n",
       "      <th>source</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2021-01-04 20:59:58+00:00</td>\n",
       "      <td>52.755</td>\n",
       "      <td>55.00</td>\n",
       "      <td>100.0</td>\n",
       "      <td>52.30</td>\n",
       "      <td>234.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2021-01-04 20:59:57+00:00</td>\n",
       "      <td>52.745</td>\n",
       "      <td>55.00</td>\n",
       "      <td>100.0</td>\n",
       "      <td>52.74</td>\n",
       "      <td>200.0</td>\n",
       "      <td>870885.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2021-01-04 20:59:54+00:00</td>\n",
       "      <td>52.745</td>\n",
       "      <td>55.00</td>\n",
       "      <td>100.0</td>\n",
       "      <td>52.30</td>\n",
       "      <td>234.0</td>\n",
       "      <td>870641.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2021-01-04 20:59:51+00:00</td>\n",
       "      <td>52.740</td>\n",
       "      <td>55.00</td>\n",
       "      <td>100.0</td>\n",
       "      <td>52.30</td>\n",
       "      <td>234.0</td>\n",
       "      <td>870341.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2021-01-04 20:59:49+00:00</td>\n",
       "      <td>52.725</td>\n",
       "      <td>52.73</td>\n",
       "      <td>600.0</td>\n",
       "      <td>52.71</td>\n",
       "      <td>300.0</td>\n",
       "      <td>868833.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>2021-01-04 19:01:07+00:00</td>\n",
       "      <td>52.490</td>\n",
       "      <td>52.50</td>\n",
       "      <td>100.0</td>\n",
       "      <td>52.48</td>\n",
       "      <td>200.0</td>\n",
       "      <td>582993.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>2021-01-04 19:01:03+00:00</td>\n",
       "      <td>52.510</td>\n",
       "      <td>52.50</td>\n",
       "      <td>200.0</td>\n",
       "      <td>52.49</td>\n",
       "      <td>200.0</td>\n",
       "      <td>582493.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>2021-01-04 19:01:02+00:00</td>\n",
       "      <td>52.495</td>\n",
       "      <td>52.51</td>\n",
       "      <td>200.0</td>\n",
       "      <td>52.49</td>\n",
       "      <td>200.0</td>\n",
       "      <td>582093.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>2021-01-04 19:00:59+00:00</td>\n",
       "      <td>52.510</td>\n",
       "      <td>52.51</td>\n",
       "      <td>200.0</td>\n",
       "      <td>52.50</td>\n",
       "      <td>200.0</td>\n",
       "      <td>580893.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>2021-01-04 19:00:51+00:00</td>\n",
       "      <td>52.505</td>\n",
       "      <td>52.51</td>\n",
       "      <td>200.0</td>\n",
       "      <td>52.50</td>\n",
       "      <td>100.0</td>\n",
       "      <td>580793.0</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                         time  last_price  ask_price  ask_size  bid_price  \\\n",
       "0   2021-01-04 20:59:58+00:00      52.755      55.00     100.0      52.30   \n",
       "1   2021-01-04 20:59:57+00:00      52.745      55.00     100.0      52.74   \n",
       "2   2021-01-04 20:59:54+00:00      52.745      55.00     100.0      52.30   \n",
       "3   2021-01-04 20:59:51+00:00      52.740      55.00     100.0      52.30   \n",
       "4   2021-01-04 20:59:49+00:00      52.725      52.73     600.0      52.71   \n",
       "..                        ...         ...        ...       ...        ...   \n",
       "995 2021-01-04 19:01:07+00:00      52.490      52.50     100.0      52.48   \n",
       "996 2021-01-04 19:01:03+00:00      52.510      52.50     200.0      52.49   \n",
       "997 2021-01-04 19:01:02+00:00      52.495      52.51     200.0      52.49   \n",
       "998 2021-01-04 19:00:59+00:00      52.510      52.51     200.0      52.50   \n",
       "999 2021-01-04 19:00:51+00:00      52.505      52.51     200.0      52.50   \n",
       "\n",
       "     bid_size    volume source  \n",
       "0       234.0       0.0   None  \n",
       "1       200.0  870885.0   None  \n",
       "2       234.0  870641.0   None  \n",
       "3       234.0  870341.0   None  \n",
       "4       300.0  868833.0   None  \n",
       "..        ...       ...    ...  \n",
       "995     200.0  582993.0   None  \n",
       "996     200.0  582493.0   None  \n",
       "997     200.0  582093.0   None  \n",
       "998     200.0  580893.0   None  \n",
       "999     100.0  580793.0   None  \n",
       "\n",
       "[1000 rows x 8 columns]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response = (\n",
    "    security_api.get_security_intraday_prices(identifier=\"KO\", \n",
    "                                              start_date=\"2021-01-02\",\n",
    "                                              end_date=\"2021-01-05\",\n",
    "                                              page_size=1000)\n",
    "    )\n",
    "df = pd.DataFrame(response.intraday_prices_dict)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5. Get Coca-Cola's latest earnings record:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'board_of_directors_meeting_date': None,\n",
      " 'board_of_directors_meeting_type': None,\n",
      " 'broadcast_url': 'http://mmm.wallstreethorizon.com/u.asp?u=347366',\n",
      " 'company_website': 'http://mmm.wallstreethorizon.com/u.asp?u=14711',\n",
      " 'conference_call_date': datetime.date(2020, 10, 22),\n",
      " 'conference_call_passcode': None,\n",
      " 'conference_call_phone_number': None,\n",
      " 'conference_call_time': '8:30 AM',\n",
      " 'last_confirmation_date': datetime.date(2020, 9, 23),\n",
      " 'next_earnings_date': datetime.date(2020, 10, 22),\n",
      " 'next_earnings_fiscal_year': 2020,\n",
      " 'next_earnings_quarter': 'Q3',\n",
      " 'preliminary_earnings_date': None,\n",
      " 'q1_date': datetime.date(2020, 4, 21),\n",
      " 'q2_date': datetime.date(2020, 7, 21),\n",
      " 'q3_date': datetime.date(2020, 10, 22),\n",
      " 'q4_date': datetime.date(2020, 1, 30),\n",
      " 'quarter': 'Q3',\n",
      " 'security': {'code': 'EQS',\n",
      "              'company_id': 'com_VXWJgv',\n",
      "              'composite_figi': 'BBG000BMX289',\n",
      "              'composite_ticker': 'KO:US',\n",
      "              'currency': 'USD',\n",
      "              'figi': 'BBG000BMX4N8',\n",
      "              'id': 'sec_X7m9Zy',\n",
      "              'name': 'Coca-Cola Co',\n",
      "              'primary_listing': True,\n",
      "              'share_class_figi': 'BBG001S5SMQ8',\n",
      "              'ticker': 'KO'},\n",
      " 'time_of_day': 'Before Market',\n",
      " 'transcript_fiscal_year': None,\n",
      " 'transcript_quarter': None,\n",
      " 'transcript_url': None,\n",
      " 'type': 'V'}\n"
     ]
    }
   ],
   "source": [
    "r = security_api.get_security_latest_earnings_record(identifier=\"KO\")\n",
    "print(r)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.4 Getting data from Alpha Vantage"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Import the libraries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from alpha_vantage.cryptocurrencies import CryptoCurrencies"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Authenticate using the personal API key and select the API:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "ALPHA_VANTAGE_API_KEY = \"YOUR_KEY_HERE\"\n",
    "\n",
    "crypto_api = CryptoCurrencies(key=ALPHA_VANTAGE_API_KEY, \n",
    "                              output_format=\"pandas\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Download the daily prices of Bitcoin, expressed in EUR:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "data, meta_data = crypto_api.get_digital_currency_daily(\n",
    "    symbol=\"BTC\", \n",
    "    market=\"EUR\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'1. Information': 'Daily Prices and Volumes for Digital Currency',\n",
       " '2. Digital Currency Code': 'BTC',\n",
       " '3. Digital Currency Name': 'Bitcoin',\n",
       " '4. Market Code': 'EUR',\n",
       " '5. Market Name': 'Euro',\n",
       " '6. Last Refreshed': '2022-04-25 00:00:00',\n",
       " '7. Time Zone': 'UTC'}"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "meta_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1a. open (EUR)</th>\n",
       "      <th>1b. open (USD)</th>\n",
       "      <th>2a. high (EUR)</th>\n",
       "      <th>2b. high (USD)</th>\n",
       "      <th>3a. low (EUR)</th>\n",
       "      <th>3b. low (USD)</th>\n",
       "      <th>4a. close (EUR)</th>\n",
       "      <th>4b. close (USD)</th>\n",
       "      <th>5. volume</th>\n",
       "      <th>6. market cap (USD)</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-04-25</th>\n",
       "      <td>36491.36100</td>\n",
       "      <td>39450.12</td>\n",
       "      <td>36538.27700</td>\n",
       "      <td>39500.84</td>\n",
       "      <td>35870.45475</td>\n",
       "      <td>38778.87</td>\n",
       "      <td>36130.50000</td>\n",
       "      <td>39060.00</td>\n",
       "      <td>3032.078540</td>\n",
       "      <td>3032.078540</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-24</th>\n",
       "      <td>36483.48925</td>\n",
       "      <td>39441.61</td>\n",
       "      <td>36944.50000</td>\n",
       "      <td>39940.00</td>\n",
       "      <td>36009.89850</td>\n",
       "      <td>38929.62</td>\n",
       "      <td>36491.37025</td>\n",
       "      <td>39450.13</td>\n",
       "      <td>26703.611860</td>\n",
       "      <td>26703.611860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-23</th>\n",
       "      <td>36731.00075</td>\n",
       "      <td>39709.19</td>\n",
       "      <td>36981.50000</td>\n",
       "      <td>39980.00</td>\n",
       "      <td>36338.62500</td>\n",
       "      <td>39285.00</td>\n",
       "      <td>36483.48000</td>\n",
       "      <td>39441.60</td>\n",
       "      <td>20291.423750</td>\n",
       "      <td>20291.423750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-22</th>\n",
       "      <td>37444.00925</td>\n",
       "      <td>40480.01</td>\n",
       "      <td>37735.43050</td>\n",
       "      <td>40795.06</td>\n",
       "      <td>36238.72500</td>\n",
       "      <td>39177.00</td>\n",
       "      <td>36730.99150</td>\n",
       "      <td>39709.18</td>\n",
       "      <td>46664.019600</td>\n",
       "      <td>46664.019600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-21</th>\n",
       "      <td>38256.32575</td>\n",
       "      <td>41358.19</td>\n",
       "      <td>39752.80000</td>\n",
       "      <td>42976.00</td>\n",
       "      <td>36769.67500</td>\n",
       "      <td>39751.00</td>\n",
       "      <td>37444.00925</td>\n",
       "      <td>40480.01</td>\n",
       "      <td>59316.276570</td>\n",
       "      <td>59316.276570</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-04</th>\n",
       "      <td>10005.59550</td>\n",
       "      <td>10816.86</td>\n",
       "      <td>10212.00000</td>\n",
       "      <td>11040.00</td>\n",
       "      <td>9760.60000</td>\n",
       "      <td>10552.00</td>\n",
       "      <td>10109.53775</td>\n",
       "      <td>10929.23</td>\n",
       "      <td>39924.745141</td>\n",
       "      <td>39924.745141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-03</th>\n",
       "      <td>9734.46875</td>\n",
       "      <td>10523.75</td>\n",
       "      <td>10086.91225</td>\n",
       "      <td>10904.77</td>\n",
       "      <td>9710.58525</td>\n",
       "      <td>10497.93</td>\n",
       "      <td>10005.59550</td>\n",
       "      <td>10816.86</td>\n",
       "      <td>33802.318824</td>\n",
       "      <td>33802.318824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-02</th>\n",
       "      <td>9596.87500</td>\n",
       "      <td>10375.00</td>\n",
       "      <td>9869.75000</td>\n",
       "      <td>10670.00</td>\n",
       "      <td>9510.24875</td>\n",
       "      <td>10281.35</td>\n",
       "      <td>9734.46875</td>\n",
       "      <td>10523.75</td>\n",
       "      <td>42990.444221</td>\n",
       "      <td>42990.444221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-01</th>\n",
       "      <td>9324.49025</td>\n",
       "      <td>10080.53</td>\n",
       "      <td>9682.77050</td>\n",
       "      <td>10467.86</td>\n",
       "      <td>9123.70050</td>\n",
       "      <td>9863.46</td>\n",
       "      <td>9596.86575</td>\n",
       "      <td>10374.99</td>\n",
       "      <td>41727.637028</td>\n",
       "      <td>41727.637028</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-07-31</th>\n",
       "      <td>8856.87500</td>\n",
       "      <td>9575.00</td>\n",
       "      <td>9351.56500</td>\n",
       "      <td>10109.80</td>\n",
       "      <td>8838.37500</td>\n",
       "      <td>9555.00</td>\n",
       "      <td>9324.49025</td>\n",
       "      <td>10080.53</td>\n",
       "      <td>39515.354560</td>\n",
       "      <td>39515.354560</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            1a. open (EUR)  1b. open (USD)  2a. high (EUR)  2b. high (USD)  \\\n",
       "date                                                                         \n",
       "2022-04-25     36491.36100        39450.12     36538.27700        39500.84   \n",
       "2022-04-24     36483.48925        39441.61     36944.50000        39940.00   \n",
       "2022-04-23     36731.00075        39709.19     36981.50000        39980.00   \n",
       "2022-04-22     37444.00925        40480.01     37735.43050        40795.06   \n",
       "2022-04-21     38256.32575        41358.19     39752.80000        42976.00   \n",
       "...                    ...             ...             ...             ...   \n",
       "2019-08-04     10005.59550        10816.86     10212.00000        11040.00   \n",
       "2019-08-03      9734.46875        10523.75     10086.91225        10904.77   \n",
       "2019-08-02      9596.87500        10375.00      9869.75000        10670.00   \n",
       "2019-08-01      9324.49025        10080.53      9682.77050        10467.86   \n",
       "2019-07-31      8856.87500         9575.00      9351.56500        10109.80   \n",
       "\n",
       "            3a. low (EUR)  3b. low (USD)  4a. close (EUR)  4b. close (USD)  \\\n",
       "date                                                                         \n",
       "2022-04-25    35870.45475       38778.87      36130.50000         39060.00   \n",
       "2022-04-24    36009.89850       38929.62      36491.37025         39450.13   \n",
       "2022-04-23    36338.62500       39285.00      36483.48000         39441.60   \n",
       "2022-04-22    36238.72500       39177.00      36730.99150         39709.18   \n",
       "2022-04-21    36769.67500       39751.00      37444.00925         40480.01   \n",
       "...                   ...            ...              ...              ...   \n",
       "2019-08-04     9760.60000       10552.00      10109.53775         10929.23   \n",
       "2019-08-03     9710.58525       10497.93      10005.59550         10816.86   \n",
       "2019-08-02     9510.24875       10281.35       9734.46875         10523.75   \n",
       "2019-08-01     9123.70050        9863.46       9596.86575         10374.99   \n",
       "2019-07-31     8838.37500        9555.00       9324.49025         10080.53   \n",
       "\n",
       "               5. volume  6. market cap (USD)  \n",
       "date                                           \n",
       "2022-04-25   3032.078540          3032.078540  \n",
       "2022-04-24  26703.611860         26703.611860  \n",
       "2022-04-23  20291.423750         20291.423750  \n",
       "2022-04-22  46664.019600         46664.019600  \n",
       "2022-04-21  59316.276570         59316.276570  \n",
       "...                  ...                  ...  \n",
       "2019-08-04  39924.745141         39924.745141  \n",
       "2019-08-03  33802.318824         33802.318824  \n",
       "2019-08-02  42990.444221         42990.444221  \n",
       "2019-08-01  41727.637028         41727.637028  \n",
       "2019-07-31  39515.354560         39515.354560  \n",
       "\n",
       "[1000 rows x 10 columns]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "4. Download the realtime exchange rate:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Realtime Currency Exchange Rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1. From_Currency Code</th>\n",
       "      <td>BTC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2. From_Currency Name</th>\n",
       "      <td>Bitcoin</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3. To_Currency Code</th>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4. To_Currency Name</th>\n",
       "      <td>United States Dollar</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5. Exchange Rate</th>\n",
       "      <td>22480.74000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6. Last Refreshed</th>\n",
       "      <td>2022-08-04 19:58:01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7. Time Zone</th>\n",
       "      <td>UTC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8. Bid Price</th>\n",
       "      <td>22480.76000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9. Ask Price</th>\n",
       "      <td>22481.69000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      Realtime Currency Exchange Rate\n",
       "1. From_Currency Code                             BTC\n",
       "2. From_Currency Name                         Bitcoin\n",
       "3. To_Currency Code                               USD\n",
       "4. To_Currency Name              United States Dollar\n",
       "5. Exchange Rate                       22480.74000000\n",
       "6. Last Refreshed                 2022-08-04 19:58:01\n",
       "7. Time Zone                                      UTC\n",
       "8. Bid Price                           22480.76000000\n",
       "9. Ask Price                           22481.69000000"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "crypto_api.get_digital_currency_exchange_rate(\n",
    "    from_currency=\"BTC\", \n",
    "    to_currency=\"USD\"\n",
    ")[0].transpose()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "### There's more"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Import the libraries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import pandas as pd\n",
    "from io import BytesIO"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Download Bitcoin's intraday data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1. open</th>\n",
       "      <th>2. high</th>\n",
       "      <th>3. low</th>\n",
       "      <th>4. close</th>\n",
       "      <th>5. volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-04-25 22:00:00</th>\n",
       "      <td>3008.00000</td>\n",
       "      <td>3017.93000</td>\n",
       "      <td>3003.73000</td>\n",
       "      <td>3006.70000</td>\n",
       "      <td>4288</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-25 21:30:00</th>\n",
       "      <td>2995.48000</td>\n",
       "      <td>3008.26000</td>\n",
       "      <td>2993.91000</td>\n",
       "      <td>3007.99000</td>\n",
       "      <td>2438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-25 21:00:00</th>\n",
       "      <td>2999.55000</td>\n",
       "      <td>3007.93000</td>\n",
       "      <td>2995.22000</td>\n",
       "      <td>2995.48000</td>\n",
       "      <td>4337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-25 20:30:00</th>\n",
       "      <td>3000.30000</td>\n",
       "      <td>3009.41000</td>\n",
       "      <td>2989.99000</td>\n",
       "      <td>2999.54000</td>\n",
       "      <td>7413</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-25 20:00:00</th>\n",
       "      <td>3012.41000</td>\n",
       "      <td>3025.65000</td>\n",
       "      <td>2998.33000</td>\n",
       "      <td>3000.30000</td>\n",
       "      <td>13815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-05 04:30:00</th>\n",
       "      <td>3518.98000</td>\n",
       "      <td>3534.88000</td>\n",
       "      <td>3517.80000</td>\n",
       "      <td>3524.08000</td>\n",
       "      <td>4881</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-05 04:00:00</th>\n",
       "      <td>3523.91000</td>\n",
       "      <td>3533.51000</td>\n",
       "      <td>3516.66000</td>\n",
       "      <td>3518.98000</td>\n",
       "      <td>3680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-05 03:30:00</th>\n",
       "      <td>3523.36000</td>\n",
       "      <td>3535.61000</td>\n",
       "      <td>3521.04000</td>\n",
       "      <td>3523.92000</td>\n",
       "      <td>4739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-05 03:00:00</th>\n",
       "      <td>3514.89000</td>\n",
       "      <td>3527.99000</td>\n",
       "      <td>3514.53000</td>\n",
       "      <td>3523.35000</td>\n",
       "      <td>5492</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-05 02:30:00</th>\n",
       "      <td>3518.00000</td>\n",
       "      <td>3518.00000</td>\n",
       "      <td>3509.95000</td>\n",
       "      <td>3514.89000</td>\n",
       "      <td>3197</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        1. open     2. high      3. low    4. close 5. volume\n",
       "2022-04-25 22:00:00  3008.00000  3017.93000  3003.73000  3006.70000      4288\n",
       "2022-04-25 21:30:00  2995.48000  3008.26000  2993.91000  3007.99000      2438\n",
       "2022-04-25 21:00:00  2999.55000  3007.93000  2995.22000  2995.48000      4337\n",
       "2022-04-25 20:30:00  3000.30000  3009.41000  2989.99000  2999.54000      7413\n",
       "2022-04-25 20:00:00  3012.41000  3025.65000  2998.33000  3000.30000     13815\n",
       "...                         ...         ...         ...         ...       ...\n",
       "2022-04-05 04:30:00  3518.98000  3534.88000  3517.80000  3524.08000      4881\n",
       "2022-04-05 04:00:00  3523.91000  3533.51000  3516.66000  3518.98000      3680\n",
       "2022-04-05 03:30:00  3523.36000  3535.61000  3521.04000  3523.92000      4739\n",
       "2022-04-05 03:00:00  3514.89000  3527.99000  3514.53000  3523.35000      5492\n",
       "2022-04-05 02:30:00  3518.00000  3518.00000  3509.95000  3514.89000      3197\n",
       "\n",
       "[1000 rows x 5 columns]"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AV_API_URL = \"https://www.alphavantage.co/query\"\n",
    "parameters = {\n",
    "    \"function\": \"CRYPTO_INTRADAY\",\n",
    "    \"symbol\": \"ETH\",\n",
    "    \"market\": \"USD\",\n",
    "    \"interval\": \"30min\",\n",
    "    \"outputsize\": \"full\",\n",
    "    \"apikey\": ALPHA_VANTAGE_API_KEY\n",
    "}\n",
    "r = requests.get(AV_API_URL, params=parameters)\n",
    "data = r.json()\n",
    "df = (\n",
    "    pd.DataFrame(data[\"Time Series Crypto (30min)\"])\n",
    "    .transpose()\n",
    ")\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Download the upcoming earnings announcements:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "      <th>reportDate</th>\n",
       "      <th>fiscalDateEnding</th>\n",
       "      <th>estimate</th>\n",
       "      <th>currency</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>Agilent Technologies Inc</td>\n",
       "      <td>2022-05-23</td>\n",
       "      <td>2022-04-30</td>\n",
       "      <td>1.12</td>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AA</td>\n",
       "      <td>Alcoa Corp</td>\n",
       "      <td>2022-07-13</td>\n",
       "      <td>2022-06-30</td>\n",
       "      <td>3.56</td>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AACG</td>\n",
       "      <td>ATA Creativity Global</td>\n",
       "      <td>2022-05-11</td>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>-0.25</td>\n",
       "      <td>CNY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AADI</td>\n",
       "      <td>Aadi Bioscience Inc</td>\n",
       "      <td>2022-05-16</td>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>-0.71</td>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AAIC</td>\n",
       "      <td>Arlington Asset Investment Corp - Class A</td>\n",
       "      <td>2022-05-04</td>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>0.03</td>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5308</th>\n",
       "      <td>ZWS</td>\n",
       "      <td>Zurn Water Solutions Corp</td>\n",
       "      <td>2022-04-26</td>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>0.22</td>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5309</th>\n",
       "      <td>ZY</td>\n",
       "      <td>Zymergen Inc</td>\n",
       "      <td>2022-05-12</td>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>-0.71</td>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5310</th>\n",
       "      <td>ZYME</td>\n",
       "      <td>Zymeworks Inc</td>\n",
       "      <td>2022-05-04</td>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>-1.63</td>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5311</th>\n",
       "      <td>ZYNE</td>\n",
       "      <td>Zynerba Pharmaceuticals Inc</td>\n",
       "      <td>2022-05-10</td>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>-0.23</td>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5312</th>\n",
       "      <td>ZYXI</td>\n",
       "      <td>Zynex Inc</td>\n",
       "      <td>2022-04-28</td>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>0.05</td>\n",
       "      <td>USD</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5313 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     symbol                                       name  reportDate  \\\n",
       "0         A                   Agilent Technologies Inc  2022-05-23   \n",
       "1        AA                                 Alcoa Corp  2022-07-13   \n",
       "2      AACG                      ATA Creativity Global  2022-05-11   \n",
       "3      AADI                        Aadi Bioscience Inc  2022-05-16   \n",
       "4      AAIC  Arlington Asset Investment Corp - Class A  2022-05-04   \n",
       "...     ...                                        ...         ...   \n",
       "5308    ZWS                  Zurn Water Solutions Corp  2022-04-26   \n",
       "5309     ZY                               Zymergen Inc  2022-05-12   \n",
       "5310   ZYME                              Zymeworks Inc  2022-05-04   \n",
       "5311   ZYNE                Zynerba Pharmaceuticals Inc  2022-05-10   \n",
       "5312   ZYXI                                  Zynex Inc  2022-04-28   \n",
       "\n",
       "     fiscalDateEnding  estimate currency  \n",
       "0          2022-04-30      1.12      USD  \n",
       "1          2022-06-30      3.56      USD  \n",
       "2          2022-03-31     -0.25      CNY  \n",
       "3          2022-03-31     -0.71      USD  \n",
       "4          2022-03-31      0.03      USD  \n",
       "...               ...       ...      ...  \n",
       "5308       2022-03-31      0.22      USD  \n",
       "5309       2022-03-31     -0.71      USD  \n",
       "5310       2022-03-31     -1.63      USD  \n",
       "5311       2022-03-31     -0.23      USD  \n",
       "5312       2022-03-31      0.05      USD  \n",
       "\n",
       "[5313 rows x 6 columns]"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AV_API_URL = \"https://www.alphavantage.co/query\" \n",
    "parameters = {\n",
    "    \"function\": \"EARNINGS_CALENDAR\",\n",
    "    \"horizon\": \"3month\",\n",
    "    \"apikey\": ALPHA_VANTAGE_API_KEY\n",
    "}\n",
    "\n",
    "r = requests.get(AV_API_URL, params=parameters)\n",
    "pd.read_csv(BytesIO(r.content))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bytes"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(r.content)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "### Bonus\n",
    "\n",
    "This section includes some additional short recipes not published in the book."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Get Tesla's earnings:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "AV_API_URL = \"https://www.alphavantage.co/query\" \n",
    "parameters = {\n",
    "    \"function\": \"EARNINGS\",\n",
    "    \"symbol\": \"TSLA\", \n",
    "    \"apikey\": ALPHA_VANTAGE_API_KEY\n",
    "}\n",
    "r = requests.get(AV_API_URL,  params=parameters)\n",
    "data = r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['symbol', 'annualEarnings', 'quarterlyEarnings'])"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fiscalDateEnding</th>\n",
       "      <th>reportedDate</th>\n",
       "      <th>reportedEPS</th>\n",
       "      <th>estimatedEPS</th>\n",
       "      <th>surprise</th>\n",
       "      <th>surprisePercentage</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-03-31</td>\n",
       "      <td>2022-04-20</td>\n",
       "      <td>3.22</td>\n",
       "      <td>2.26</td>\n",
       "      <td>0.96</td>\n",
       "      <td>42.4779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2021-12-31</td>\n",
       "      <td>2022-01-26</td>\n",
       "      <td>2.54</td>\n",
       "      <td>2.37</td>\n",
       "      <td>0.17</td>\n",
       "      <td>7.173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2021-09-30</td>\n",
       "      <td>2021-10-20</td>\n",
       "      <td>1.86</td>\n",
       "      <td>1.6143</td>\n",
       "      <td>0.2457</td>\n",
       "      <td>15.2202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2021-06-30</td>\n",
       "      <td>2021-07-26</td>\n",
       "      <td>1.45</td>\n",
       "      <td>0.9789</td>\n",
       "      <td>0.4711</td>\n",
       "      <td>48.1254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2021-03-31</td>\n",
       "      <td>2021-04-26</td>\n",
       "      <td>0.93</td>\n",
       "      <td>0.7787</td>\n",
       "      <td>0.1513</td>\n",
       "      <td>19.4298</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  fiscalDateEnding reportedDate reportedEPS estimatedEPS surprise  \\\n",
       "0       2022-03-31   2022-04-20        3.22         2.26     0.96   \n",
       "1       2021-12-31   2022-01-26        2.54         2.37     0.17   \n",
       "2       2021-09-30   2021-10-20        1.86       1.6143   0.2457   \n",
       "3       2021-06-30   2021-07-26        1.45       0.9789   0.4711   \n",
       "4       2021-03-31   2021-04-26        0.93       0.7787   0.1513   \n",
       "\n",
       "  surprisePercentage  \n",
       "0            42.4779  \n",
       "1              7.173  \n",
       "2            15.2202  \n",
       "3            48.1254  \n",
       "4            19.4298  "
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data[\"quarterlyEarnings\"])\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Download the upcoming IPOs:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>{}</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [{}]\n",
       "Index: []"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import csv\n",
    "\n",
    "AV_API_URL = \"https://www.alphavantage.co/query\" \n",
    "parameters = {\n",
    "    \"function\": \"IPO_CALENDAR\",\n",
    "    \"apikey\": ALPHA_VANTAGE_API_KEY\n",
    "}\n",
    "\n",
    "with requests.Session() as s:\n",
    "    download = s.get(AV_API_URL, params=parameters)\n",
    "    decoded_content = download.content.decode(\"utf-8\")\n",
    "    ipos_list = list(csv.reader(decoded_content.splitlines(), delimiter=\",\"))\n",
    "\n",
    "df = pd.DataFrame(ipos_list[1:], columns=ipos_list[0])\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Download Google's stock prices using the `TimeSeries` module:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloaded 4452 observations\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1. open</th>\n",
       "      <th>2. high</th>\n",
       "      <th>3. low</th>\n",
       "      <th>4. close</th>\n",
       "      <th>5. volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-04-25</th>\n",
       "      <td>2382.02</td>\n",
       "      <td>2465.55</td>\n",
       "      <td>2370.22</td>\n",
       "      <td>2461.480</td>\n",
       "      <td>2293404.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-22</th>\n",
       "      <td>2500.00</td>\n",
       "      <td>2508.04</td>\n",
       "      <td>2378.50</td>\n",
       "      <td>2392.710</td>\n",
       "      <td>2844186.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-21</th>\n",
       "      <td>2585.00</td>\n",
       "      <td>2601.97</td>\n",
       "      <td>2490.53</td>\n",
       "      <td>2496.290</td>\n",
       "      <td>1822258.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-20</th>\n",
       "      <td>2617.84</td>\n",
       "      <td>2627.98</td>\n",
       "      <td>2550.00</td>\n",
       "      <td>2560.800</td>\n",
       "      <td>1573067.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-19</th>\n",
       "      <td>2553.83</td>\n",
       "      <td>2606.66</td>\n",
       "      <td>2539.99</td>\n",
       "      <td>2600.180</td>\n",
       "      <td>1324488.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2004-08-25</th>\n",
       "      <td>104.76</td>\n",
       "      <td>108.00</td>\n",
       "      <td>103.88</td>\n",
       "      <td>106.000</td>\n",
       "      <td>9188600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2004-08-24</th>\n",
       "      <td>111.24</td>\n",
       "      <td>111.60</td>\n",
       "      <td>103.57</td>\n",
       "      <td>104.870</td>\n",
       "      <td>15247300.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2004-08-23</th>\n",
       "      <td>110.76</td>\n",
       "      <td>113.48</td>\n",
       "      <td>109.05</td>\n",
       "      <td>109.400</td>\n",
       "      <td>18256100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2004-08-20</th>\n",
       "      <td>101.01</td>\n",
       "      <td>109.08</td>\n",
       "      <td>100.50</td>\n",
       "      <td>108.310</td>\n",
       "      <td>22834300.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2004-08-19</th>\n",
       "      <td>100.01</td>\n",
       "      <td>104.06</td>\n",
       "      <td>95.96</td>\n",
       "      <td>100.335</td>\n",
       "      <td>44659000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4452 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            1. open  2. high   3. low  4. close   5. volume\n",
       "date                                                       \n",
       "2022-04-25  2382.02  2465.55  2370.22  2461.480   2293404.0\n",
       "2022-04-22  2500.00  2508.04  2378.50  2392.710   2844186.0\n",
       "2022-04-21  2585.00  2601.97  2490.53  2496.290   1822258.0\n",
       "2022-04-20  2617.84  2627.98  2550.00  2560.800   1573067.0\n",
       "2022-04-19  2553.83  2606.66  2539.99  2600.180   1324488.0\n",
       "...             ...      ...      ...       ...         ...\n",
       "2004-08-25   104.76   108.00   103.88   106.000   9188600.0\n",
       "2004-08-24   111.24   111.60   103.57   104.870  15247300.0\n",
       "2004-08-23   110.76   113.48   109.05   109.400  18256100.0\n",
       "2004-08-20   101.01   109.08   100.50   108.310  22834300.0\n",
       "2004-08-19   100.01   104.06    95.96   100.335  44659000.0\n",
       "\n",
       "[4452 rows x 5 columns]"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from alpha_vantage.timeseries import TimeSeries\n",
    "\n",
    "ts = TimeSeries(key=ALPHA_VANTAGE_API_KEY, output_format=\"pandas\")\n",
    "data, _ = ts.get_daily(\"GOOGL\", outputsize=\"full\")\n",
    "print(f\"Downloaded {len(data)} observations\")\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. Similarly, we can download the intraday prices:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1. open</th>\n",
       "      <th>2. high</th>\n",
       "      <th>3. low</th>\n",
       "      <th>4. close</th>\n",
       "      <th>5. volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-04-22 19:30:00</th>\n",
       "      <td>2388.0000</td>\n",
       "      <td>2388.0000</td>\n",
       "      <td>2388.0000</td>\n",
       "      <td>2388.0000</td>\n",
       "      <td>205.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-22 18:05:00</th>\n",
       "      <td>2388.0000</td>\n",
       "      <td>2388.0000</td>\n",
       "      <td>2388.0000</td>\n",
       "      <td>2388.0000</td>\n",
       "      <td>210.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-22 18:00:00</th>\n",
       "      <td>2389.2300</td>\n",
       "      <td>2389.2300</td>\n",
       "      <td>2389.2300</td>\n",
       "      <td>2389.2300</td>\n",
       "      <td>475.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-22 17:55:00</th>\n",
       "      <td>2389.0644</td>\n",
       "      <td>2389.0644</td>\n",
       "      <td>2389.0644</td>\n",
       "      <td>2389.0644</td>\n",
       "      <td>299.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-04-22 17:45:00</th>\n",
       "      <td>2389.0000</td>\n",
       "      <td>2389.0000</td>\n",
       "      <td>2389.0000</td>\n",
       "      <td>2389.0000</td>\n",
       "      <td>129.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-03-28 08:15:00</th>\n",
       "      <td>2835.9000</td>\n",
       "      <td>2835.9000</td>\n",
       "      <td>2835.9000</td>\n",
       "      <td>2835.9000</td>\n",
       "      <td>960.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-03-28 08:05:00</th>\n",
       "      <td>2836.3572</td>\n",
       "      <td>2836.3572</td>\n",
       "      <td>2835.0000</td>\n",
       "      <td>2835.0000</td>\n",
       "      <td>15340.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-03-28 07:35:00</th>\n",
       "      <td>2835.0000</td>\n",
       "      <td>2835.0000</td>\n",
       "      <td>2835.0000</td>\n",
       "      <td>2835.0000</td>\n",
       "      <td>696.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-03-28 07:15:00</th>\n",
       "      <td>2833.1700</td>\n",
       "      <td>2833.1700</td>\n",
       "      <td>2833.1700</td>\n",
       "      <td>2833.1700</td>\n",
       "      <td>265.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-03-28 07:05:00</th>\n",
       "      <td>2836.7900</td>\n",
       "      <td>2836.7900</td>\n",
       "      <td>2836.7900</td>\n",
       "      <td>2836.7900</td>\n",
       "      <td>102.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1836 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       1. open    2. high     3. low   4. close  5. volume\n",
       "date                                                                      \n",
       "2022-04-22 19:30:00  2388.0000  2388.0000  2388.0000  2388.0000      205.0\n",
       "2022-04-22 18:05:00  2388.0000  2388.0000  2388.0000  2388.0000      210.0\n",
       "2022-04-22 18:00:00  2389.2300  2389.2300  2389.2300  2389.2300      475.0\n",
       "2022-04-22 17:55:00  2389.0644  2389.0644  2389.0644  2389.0644      299.0\n",
       "2022-04-22 17:45:00  2389.0000  2389.0000  2389.0000  2389.0000      129.0\n",
       "...                        ...        ...        ...        ...        ...\n",
       "2022-03-28 08:15:00  2835.9000  2835.9000  2835.9000  2835.9000      960.0\n",
       "2022-03-28 08:05:00  2836.3572  2836.3572  2835.0000  2835.0000    15340.0\n",
       "2022-03-28 07:35:00  2835.0000  2835.0000  2835.0000  2835.0000      696.0\n",
       "2022-03-28 07:15:00  2833.1700  2833.1700  2833.1700  2833.1700      265.0\n",
       "2022-03-28 07:05:00  2836.7900  2836.7900  2836.7900  2836.7900      102.0\n",
       "\n",
       "[1836 rows x 5 columns]"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data, _ = ts.get_intraday(\"GOOGL\", interval=\"5min\", outputsize=\"full\")\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "## 1.5 Getting data from CoinGecko"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to do it..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Import the libraries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pycoingecko import CoinGeckoAPI\n",
    "from datetime import datetime\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Instantiate the CoinGecko API:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "cg = CoinGeckoAPI()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Get Bitcoin's OHLC prices from the last 14 days:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-04-12 00:00:00</td>\n",
       "      <td>39897.10</td>\n",
       "      <td>39897.10</td>\n",
       "      <td>39897.10</td>\n",
       "      <td>39897.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-04-12 04:00:00</td>\n",
       "      <td>39552.83</td>\n",
       "      <td>39764.83</td>\n",
       "      <td>39484.03</td>\n",
       "      <td>39484.03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-04-12 08:00:00</td>\n",
       "      <td>39729.31</td>\n",
       "      <td>40185.41</td>\n",
       "      <td>39729.31</td>\n",
       "      <td>39962.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-04-12 12:00:00</td>\n",
       "      <td>40177.06</td>\n",
       "      <td>40257.75</td>\n",
       "      <td>40177.06</td>\n",
       "      <td>40236.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-04-12 16:00:00</td>\n",
       "      <td>40416.97</td>\n",
       "      <td>40659.51</td>\n",
       "      <td>40055.52</td>\n",
       "      <td>40055.52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>2022-04-25 08:00:00</td>\n",
       "      <td>39267.69</td>\n",
       "      <td>39267.69</td>\n",
       "      <td>38786.55</td>\n",
       "      <td>38786.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>2022-04-25 12:00:00</td>\n",
       "      <td>38492.00</td>\n",
       "      <td>38623.92</td>\n",
       "      <td>38464.03</td>\n",
       "      <td>38494.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>2022-04-25 16:00:00</td>\n",
       "      <td>38823.01</td>\n",
       "      <td>39091.84</td>\n",
       "      <td>38823.01</td>\n",
       "      <td>39091.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>2022-04-25 20:00:00</td>\n",
       "      <td>39052.60</td>\n",
       "      <td>40071.76</td>\n",
       "      <td>39052.60</td>\n",
       "      <td>40071.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>2022-04-26 00:00:00</td>\n",
       "      <td>40259.97</td>\n",
       "      <td>40259.97</td>\n",
       "      <td>40153.33</td>\n",
       "      <td>40153.33</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>85 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  date      open      high       low     close\n",
       "0  2022-04-12 00:00:00  39897.10  39897.10  39897.10  39897.10\n",
       "1  2022-04-12 04:00:00  39552.83  39764.83  39484.03  39484.03\n",
       "2  2022-04-12 08:00:00  39729.31  40185.41  39729.31  39962.04\n",
       "3  2022-04-12 12:00:00  40177.06  40257.75  40177.06  40236.72\n",
       "4  2022-04-12 16:00:00  40416.97  40659.51  40055.52  40055.52\n",
       "..                 ...       ...       ...       ...       ...\n",
       "80 2022-04-25 08:00:00  39267.69  39267.69  38786.55  38786.55\n",
       "81 2022-04-25 12:00:00  38492.00  38623.92  38464.03  38494.12\n",
       "82 2022-04-25 16:00:00  38823.01  39091.84  38823.01  39091.84\n",
       "83 2022-04-25 20:00:00  39052.60  40071.76  39052.60  40071.76\n",
       "84 2022-04-26 00:00:00  40259.97  40259.97  40153.33  40153.33\n",
       "\n",
       "[85 rows x 5 columns]"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ohlc = cg.get_coin_ohlc_by_id(\n",
    "    id=\"bitcoin\", vs_currency=\"usd\", days=\"14\"\n",
    ")\n",
    "ohlc_df = pd.DataFrame(ohlc)\n",
    "ohlc_df.columns = [\"date\", \"open\", \"high\", \"low\", \"close\"]\n",
    "ohlc_df[\"date\"] = pd.to_datetime(ohlc_df[\"date\"], unit=\"ms\")\n",
    "ohlc_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### There's more"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Get the top 7 trending coins (based on the # of searches in the last 24h) from CoinGecko:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>coin_id</th>\n",
       "      <th>name</th>\n",
       "      <th>symbol</th>\n",
       "      <th>market_cap_rank</th>\n",
       "      <th>slug</th>\n",
       "      <th>price_btc</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>dogecoin</td>\n",
       "      <td>5</td>\n",
       "      <td>Dogecoin</td>\n",
       "      <td>DOGE</td>\n",
       "      <td>10</td>\n",
       "      <td>dogecoin</td>\n",
       "      <td>0.000004</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>civilization</td>\n",
       "      <td>17626</td>\n",
       "      <td>Civilization</td>\n",
       "      <td>CIV</td>\n",
       "      <td>674</td>\n",
       "      <td>civilization</td>\n",
       "      <td>0.000003</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>apecoin</td>\n",
       "      <td>24383</td>\n",
       "      <td>ApeCoin</td>\n",
       "      <td>APE</td>\n",
       "      <td>31</td>\n",
       "      <td>apecoin</td>\n",
       "      <td>0.000443</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>oasis-network</td>\n",
       "      <td>13162</td>\n",
       "      <td>Oasis Network</td>\n",
       "      <td>ROSE</td>\n",
       "      <td>110</td>\n",
       "      <td>oasis-network</td>\n",
       "      <td>0.000006</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>stepn</td>\n",
       "      <td>23597</td>\n",
       "      <td>STEPN</td>\n",
       "      <td>GMT</td>\n",
       "      <td>61</td>\n",
       "      <td>stepn</td>\n",
       "      <td>0.000081</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>unicrypt-2</td>\n",
       "      <td>12871</td>\n",
       "      <td>UniCrypt</td>\n",
       "      <td>UNCX</td>\n",
       "      <td>927</td>\n",
       "      <td>unicrypt</td>\n",
       "      <td>0.011535</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>xcad-network</td>\n",
       "      <td>15857</td>\n",
       "      <td>XCAD Network</td>\n",
       "      <td>XCAD</td>\n",
       "      <td>399</td>\n",
       "      <td>xcad-network</td>\n",
       "      <td>0.000107</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              id  coin_id           name symbol  market_cap_rank  \\\n",
       "0       dogecoin        5       Dogecoin   DOGE               10   \n",
       "1   civilization    17626   Civilization    CIV              674   \n",
       "2        apecoin    24383        ApeCoin    APE               31   \n",
       "3  oasis-network    13162  Oasis Network   ROSE              110   \n",
       "4          stepn    23597          STEPN    GMT               61   \n",
       "5     unicrypt-2    12871       UniCrypt   UNCX              927   \n",
       "6   xcad-network    15857   XCAD Network   XCAD              399   \n",
       "\n",
       "            slug  price_btc  score  \n",
       "0       dogecoin   0.000004      0  \n",
       "1   civilization   0.000003      1  \n",
       "2        apecoin   0.000443      2  \n",
       "3  oasis-network   0.000006      3  \n",
       "4          stepn   0.000081      4  \n",
       "5       unicrypt   0.011535      5  \n",
       "6   xcad-network   0.000107      6  "
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trending_coins = cg.get_search_trending()\n",
    "(\n",
    "    pd.DataFrame([coin[\"item\"] for coin in trending_coins[\"coins\"]])\n",
    "    .drop(columns=[\"thumb\", \"small\", \"large\"])\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Get Bitcoin's current price in USD:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'bitcoin': {'usd': 40248}}"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cg.get_price(ids=\"bitcoin\", vs_currencies=\"usd\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "### Bonus\n",
    "\n",
    "This section includes some additional short recipes not published in the book."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. Get current price of ETH and BTC in USD and EUR:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'bitcoin': {'usd': 40248, 'eur': 37572},\n",
       " 'ethereum': {'usd': 3012.28, 'eur': 2812.02}}"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cg.get_price(ids=[\"bitcoin\", \"ethereum\"], vs_currencies=[\"usd\", \"eur\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. Get the current BTC/USD eschange rate, market capitalization, 24h volumne and change and the last-updated timestamp:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'bitcoin': {'usd': 40248,\n",
       "  'usd_market_cap': 765487743514.1045,\n",
       "  'usd_24h_vol': 32149632030.364124,\n",
       "  'usd_24h_change': 1.227364982790789,\n",
       "  'last_updated_at': 1650925381}}"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cg.get_price(ids=\"bitcoin\", vs_currencies=\"usd\", \n",
    "             include_market_cap=True, \n",
    "             include_24hr_vol=True, \n",
    "             include_24hr_change=True, \n",
    "             include_last_updated_at=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. Get the list of all supported coin ids, together with their name and symbol:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>01coin</td>\n",
       "      <td>zoc</td>\n",
       "      <td>01coin</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0-5x-long-algorand-token</td>\n",
       "      <td>algohalf</td>\n",
       "      <td>0.5X Long Algorand Token</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0-5x-long-altcoin-index-token</td>\n",
       "      <td>althalf</td>\n",
       "      <td>0.5X Long Altcoin Index Token</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0-5x-long-ascendex-token-token</td>\n",
       "      <td>asdhalf</td>\n",
       "      <td>0.5X Long AscendEx Token Token</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0-5x-long-bitcoin-cash-token</td>\n",
       "      <td>bchhalf</td>\n",
       "      <td>0.5X Long Bitcoin Cash Token</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13685</th>\n",
       "      <td>zyro</td>\n",
       "      <td>zyro</td>\n",
       "      <td>Zyro</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13686</th>\n",
       "      <td>zyrri</td>\n",
       "      <td>zyr</td>\n",
       "      <td>Zyrri</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13687</th>\n",
       "      <td>zytara-dollar</td>\n",
       "      <td>zusd</td>\n",
       "      <td>Zytara Dollar</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13688</th>\n",
       "      <td>zyx</td>\n",
       "      <td>zyx</td>\n",
       "      <td>ZYX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13689</th>\n",
       "      <td>zzz-finance-v2</td>\n",
       "      <td>zzzv2</td>\n",
       "      <td>zzz.finance v2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>13690 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   id    symbol  \\\n",
       "0                              01coin       zoc   \n",
       "1            0-5x-long-algorand-token  algohalf   \n",
       "2       0-5x-long-altcoin-index-token   althalf   \n",
       "3      0-5x-long-ascendex-token-token   asdhalf   \n",
       "4        0-5x-long-bitcoin-cash-token   bchhalf   \n",
       "...                               ...       ...   \n",
       "13685                            zyro      zyro   \n",
       "13686                           zyrri       zyr   \n",
       "13687                   zytara-dollar      zusd   \n",
       "13688                             zyx       zyx   \n",
       "13689                  zzz-finance-v2     zzzv2   \n",
       "\n",
       "                                 name  \n",
       "0                              01coin  \n",
       "1            0.5X Long Algorand Token  \n",
       "2       0.5X Long Altcoin Index Token  \n",
       "3      0.5X Long AscendEx Token Token  \n",
       "4        0.5X Long Bitcoin Cash Token  \n",
       "...                               ...  \n",
       "13685                            Zyro  \n",
       "13686                           Zyrri  \n",
       "13687                   Zytara Dollar  \n",
       "13688                             ZYX  \n",
       "13689                  zzz.finance v2  \n",
       "\n",
       "[13690 rows x 3 columns]"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(cg.get_coins_list())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4. Get all the coins market data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "      <th>image</th>\n",
       "      <th>current_price</th>\n",
       "      <th>market_cap</th>\n",
       "      <th>market_cap_rank</th>\n",
       "      <th>fully_diluted_valuation</th>\n",
       "      <th>total_volume</th>\n",
       "      <th>high_24h</th>\n",
       "      <th>...</th>\n",
       "      <th>total_supply</th>\n",
       "      <th>max_supply</th>\n",
       "      <th>ath</th>\n",
       "      <th>ath_change_percentage</th>\n",
       "      <th>ath_date</th>\n",
       "      <th>atl</th>\n",
       "      <th>atl_change_percentage</th>\n",
       "      <th>atl_date</th>\n",
       "      <th>roi</th>\n",
       "      <th>last_updated</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>bitcoin</td>\n",
       "      <td>btc</td>\n",
       "      <td>Bitcoin</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/1/la...</td>\n",
       "      <td>37572.000000</td>\n",
       "      <td>714522335039</td>\n",
       "      <td>1</td>\n",
       "      <td>7.888125e+11</td>\n",
       "      <td>3.001232e+10</td>\n",
       "      <td>37632.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>2.100000e+07</td>\n",
       "      <td>2.100000e+07</td>\n",
       "      <td>59717.000000</td>\n",
       "      <td>-37.09896</td>\n",
       "      <td>2021-11-10T14:24:11.849Z</td>\n",
       "      <td>51.300000</td>\n",
       "      <td>7.312353e+04</td>\n",
       "      <td>2013-07-05T00:00:00.000Z</td>\n",
       "      <td>None</td>\n",
       "      <td>2022-04-25T22:23:01.418Z</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ethereum</td>\n",
       "      <td>eth</td>\n",
       "      <td>Ethereum</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/279/...</td>\n",
       "      <td>2812.020000</td>\n",
       "      <td>338633922241</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.041017e+10</td>\n",
       "      <td>2817.950000</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4228.930000</td>\n",
       "      <td>-33.56248</td>\n",
       "      <td>2021-12-01T08:38:24.623Z</td>\n",
       "      <td>0.381455</td>\n",
       "      <td>7.364466e+05</td>\n",
       "      <td>2015-10-20T00:00:00.000Z</td>\n",
       "      <td>{'times': 99.10665754233172, 'currency': 'btc'...</td>\n",
       "      <td>2022-04-25T22:23:21.429Z</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>tether</td>\n",
       "      <td>usdt</td>\n",
       "      <td>Tether</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/325/...</td>\n",
       "      <td>0.933983</td>\n",
       "      <td>77646207939</td>\n",
       "      <td>3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.063136e+10</td>\n",
       "      <td>0.937355</td>\n",
       "      <td>...</td>\n",
       "      <td>8.312620e+10</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.130000</td>\n",
       "      <td>-17.45525</td>\n",
       "      <td>2018-07-24T00:00:00.000Z</td>\n",
       "      <td>0.533096</td>\n",
       "      <td>7.521739e+01</td>\n",
       "      <td>2015-03-02T00:00:00.000Z</td>\n",
       "      <td>None</td>\n",
       "      <td>2022-04-25T22:23:17.284Z</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>binancecoin</td>\n",
       "      <td>bnb</td>\n",
       "      <td>BNB</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/825/...</td>\n",
       "      <td>376.660000</td>\n",
       "      <td>63318435510</td>\n",
       "      <td>4</td>\n",
       "      <td>6.331844e+10</td>\n",
       "      <td>1.942997e+09</td>\n",
       "      <td>376.590000</td>\n",
       "      <td>...</td>\n",
       "      <td>1.681370e+08</td>\n",
       "      <td>1.681370e+08</td>\n",
       "      <td>583.170000</td>\n",
       "      <td>-35.42436</td>\n",
       "      <td>2021-11-26T02:58:28.000Z</td>\n",
       "      <td>0.033599</td>\n",
       "      <td>1.120718e+06</td>\n",
       "      <td>2017-10-19T00:00:00.000Z</td>\n",
       "      <td>None</td>\n",
       "      <td>2022-04-25T22:24:06.328Z</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>usd-coin</td>\n",
       "      <td>usdc</td>\n",
       "      <td>USD Coin</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/6319...</td>\n",
       "      <td>0.933715</td>\n",
       "      <td>46585230803</td>\n",
       "      <td>5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.108815e+09</td>\n",
       "      <td>0.940757</td>\n",
       "      <td>...</td>\n",
       "      <td>4.989235e+10</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.048000</td>\n",
       "      <td>-10.89265</td>\n",
       "      <td>2019-05-08T00:40:28.300Z</td>\n",
       "      <td>0.730265</td>\n",
       "      <td>2.785979e+01</td>\n",
       "      <td>2021-05-19T13:14:05.611Z</td>\n",
       "      <td>None</td>\n",
       "      <td>2022-04-25T22:23:49.388Z</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>curve-dao-token</td>\n",
       "      <td>crv</td>\n",
       "      <td>Curve DAO Token</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/1212...</td>\n",
       "      <td>2.550000</td>\n",
       "      <td>1000747435</td>\n",
       "      <td>96</td>\n",
       "      <td>8.433297e+09</td>\n",
       "      <td>2.445880e+08</td>\n",
       "      <td>2.580000</td>\n",
       "      <td>...</td>\n",
       "      <td>1.734036e+09</td>\n",
       "      <td>3.303030e+09</td>\n",
       "      <td>45.710000</td>\n",
       "      <td>-94.41294</td>\n",
       "      <td>2020-08-14T04:53:44.010Z</td>\n",
       "      <td>0.279972</td>\n",
       "      <td>8.121684e+02</td>\n",
       "      <td>2020-11-05T13:09:50.181Z</td>\n",
       "      <td>None</td>\n",
       "      <td>2022-04-25T22:24:10.774Z</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>dash</td>\n",
       "      <td>dash</td>\n",
       "      <td>Dash</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/19/l...</td>\n",
       "      <td>92.670000</td>\n",
       "      <td>991075201</td>\n",
       "      <td>97</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.456325e+08</td>\n",
       "      <td>93.440000</td>\n",
       "      <td>...</td>\n",
       "      <td>1.892000e+07</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1257.390000</td>\n",
       "      <td>-92.62767</td>\n",
       "      <td>2017-12-20T00:00:00.000Z</td>\n",
       "      <td>0.163048</td>\n",
       "      <td>5.675401e+04</td>\n",
       "      <td>2014-02-14T00:00:00.000Z</td>\n",
       "      <td>None</td>\n",
       "      <td>2022-04-25T22:25:21.188Z</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>mina-protocol</td>\n",
       "      <td>mina</td>\n",
       "      <td>Mina Protocol</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/1562...</td>\n",
       "      <td>2.080000</td>\n",
       "      <td>986106196</td>\n",
       "      <td>98</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.869614e+07</td>\n",
       "      <td>2.110000</td>\n",
       "      <td>...</td>\n",
       "      <td>9.122704e+08</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.430000</td>\n",
       "      <td>-72.06197</td>\n",
       "      <td>2021-06-01T01:42:37.064Z</td>\n",
       "      <td>0.786237</td>\n",
       "      <td>1.640692e+02</td>\n",
       "      <td>2021-07-21T02:30:02.124Z</td>\n",
       "      <td>None</td>\n",
       "      <td>2022-04-25T22:24:12.030Z</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>amp-token</td>\n",
       "      <td>amp</td>\n",
       "      <td>Amp</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/1240...</td>\n",
       "      <td>0.020194</td>\n",
       "      <td>970112051</td>\n",
       "      <td>99</td>\n",
       "      <td>2.004825e+09</td>\n",
       "      <td>2.990071e+07</td>\n",
       "      <td>0.021637</td>\n",
       "      <td>...</td>\n",
       "      <td>9.944384e+10</td>\n",
       "      <td>9.922516e+10</td>\n",
       "      <td>0.099698</td>\n",
       "      <td>-79.74358</td>\n",
       "      <td>2021-06-16T16:03:41.147Z</td>\n",
       "      <td>0.002138</td>\n",
       "      <td>8.447712e+02</td>\n",
       "      <td>2020-11-04T13:18:12.191Z</td>\n",
       "      <td>None</td>\n",
       "      <td>2022-04-25T22:24:24.243Z</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>lido-dao</td>\n",
       "      <td>ldo</td>\n",
       "      <td>Lido DAO</td>\n",
       "      <td>https://assets.coingecko.com/coins/images/1357...</td>\n",
       "      <td>3.060000</td>\n",
       "      <td>958244654</td>\n",
       "      <td>100</td>\n",
       "      <td>3.070086e+09</td>\n",
       "      <td>6.280524e+06</td>\n",
       "      <td>3.090000</td>\n",
       "      <td>...</td>\n",
       "      <td>9.963085e+08</td>\n",
       "      <td>1.000000e+09</td>\n",
       "      <td>6.250000</td>\n",
       "      <td>-51.06299</td>\n",
       "      <td>2021-08-20T08:35:20.158Z</td>\n",
       "      <td>0.427263</td>\n",
       "      <td>6.163696e+02</td>\n",
       "      <td>2021-03-23T06:56:59.032Z</td>\n",
       "      <td>None</td>\n",
       "      <td>2022-04-25T22:24:53.035Z</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 id symbol             name  \\\n",
       "0           bitcoin    btc          Bitcoin   \n",
       "1          ethereum    eth         Ethereum   \n",
       "2            tether   usdt           Tether   \n",
       "3       binancecoin    bnb              BNB   \n",
       "4          usd-coin   usdc         USD Coin   \n",
       "..              ...    ...              ...   \n",
       "95  curve-dao-token    crv  Curve DAO Token   \n",
       "96             dash   dash             Dash   \n",
       "97    mina-protocol   mina    Mina Protocol   \n",
       "98        amp-token    amp              Amp   \n",
       "99         lido-dao    ldo         Lido DAO   \n",
       "\n",
       "                                                image  current_price  \\\n",
       "0   https://assets.coingecko.com/coins/images/1/la...   37572.000000   \n",
       "1   https://assets.coingecko.com/coins/images/279/...    2812.020000   \n",
       "2   https://assets.coingecko.com/coins/images/325/...       0.933983   \n",
       "3   https://assets.coingecko.com/coins/images/825/...     376.660000   \n",
       "4   https://assets.coingecko.com/coins/images/6319...       0.933715   \n",
       "..                                                ...            ...   \n",
       "95  https://assets.coingecko.com/coins/images/1212...       2.550000   \n",
       "96  https://assets.coingecko.com/coins/images/19/l...      92.670000   \n",
       "97  https://assets.coingecko.com/coins/images/1562...       2.080000   \n",
       "98  https://assets.coingecko.com/coins/images/1240...       0.020194   \n",
       "99  https://assets.coingecko.com/coins/images/1357...       3.060000   \n",
       "\n",
       "      market_cap  market_cap_rank  fully_diluted_valuation  total_volume  \\\n",
       "0   714522335039                1             7.888125e+11  3.001232e+10   \n",
       "1   338633922241                2                      NaN  2.041017e+10   \n",
       "2    77646207939                3                      NaN  6.063136e+10   \n",
       "3    63318435510                4             6.331844e+10  1.942997e+09   \n",
       "4    46585230803                5                      NaN  5.108815e+09   \n",
       "..           ...              ...                      ...           ...   \n",
       "95    1000747435               96             8.433297e+09  2.445880e+08   \n",
       "96     991075201               97                      NaN  1.456325e+08   \n",
       "97     986106196               98                      NaN  4.869614e+07   \n",
       "98     970112051               99             2.004825e+09  2.990071e+07   \n",
       "99     958244654              100             3.070086e+09  6.280524e+06   \n",
       "\n",
       "        high_24h  ...  total_supply    max_supply           ath  \\\n",
       "0   37632.000000  ...  2.100000e+07  2.100000e+07  59717.000000   \n",
       "1    2817.950000  ...           NaN           NaN   4228.930000   \n",
       "2       0.937355  ...  8.312620e+10           NaN      1.130000   \n",
       "3     376.590000  ...  1.681370e+08  1.681370e+08    583.170000   \n",
       "4       0.940757  ...  4.989235e+10           NaN      1.048000   \n",
       "..           ...  ...           ...           ...           ...   \n",
       "95      2.580000  ...  1.734036e+09  3.303030e+09     45.710000   \n",
       "96     93.440000  ...  1.892000e+07           NaN   1257.390000   \n",
       "97      2.110000  ...  9.122704e+08           NaN      7.430000   \n",
       "98      0.021637  ...  9.944384e+10  9.922516e+10      0.099698   \n",
       "99      3.090000  ...  9.963085e+08  1.000000e+09      6.250000   \n",
       "\n",
       "    ath_change_percentage                  ath_date        atl  \\\n",
       "0               -37.09896  2021-11-10T14:24:11.849Z  51.300000   \n",
       "1               -33.56248  2021-12-01T08:38:24.623Z   0.381455   \n",
       "2               -17.45525  2018-07-24T00:00:00.000Z   0.533096   \n",
       "3               -35.42436  2021-11-26T02:58:28.000Z   0.033599   \n",
       "4               -10.89265  2019-05-08T00:40:28.300Z   0.730265   \n",
       "..                    ...                       ...        ...   \n",
       "95              -94.41294  2020-08-14T04:53:44.010Z   0.279972   \n",
       "96              -92.62767  2017-12-20T00:00:00.000Z   0.163048   \n",
       "97              -72.06197  2021-06-01T01:42:37.064Z   0.786237   \n",
       "98              -79.74358  2021-06-16T16:03:41.147Z   0.002138   \n",
       "99              -51.06299  2021-08-20T08:35:20.158Z   0.427263   \n",
       "\n",
       "    atl_change_percentage                  atl_date  \\\n",
       "0            7.312353e+04  2013-07-05T00:00:00.000Z   \n",
       "1            7.364466e+05  2015-10-20T00:00:00.000Z   \n",
       "2            7.521739e+01  2015-03-02T00:00:00.000Z   \n",
       "3            1.120718e+06  2017-10-19T00:00:00.000Z   \n",
       "4            2.785979e+01  2021-05-19T13:14:05.611Z   \n",
       "..                    ...                       ...   \n",
       "95           8.121684e+02  2020-11-05T13:09:50.181Z   \n",
       "96           5.675401e+04  2014-02-14T00:00:00.000Z   \n",
       "97           1.640692e+02  2021-07-21T02:30:02.124Z   \n",
       "98           8.447712e+02  2020-11-04T13:18:12.191Z   \n",
       "99           6.163696e+02  2021-03-23T06:56:59.032Z   \n",
       "\n",
       "                                                  roi  \\\n",
       "0                                                None   \n",
       "1   {'times': 99.10665754233172, 'currency': 'btc'...   \n",
       "2                                                None   \n",
       "3                                                None   \n",
       "4                                                None   \n",
       "..                                                ...   \n",
       "95                                               None   \n",
       "96                                               None   \n",
       "97                                               None   \n",
       "98                                               None   \n",
       "99                                               None   \n",
       "\n",
       "                last_updated  \n",
       "0   2022-04-25T22:23:01.418Z  \n",
       "1   2022-04-25T22:23:21.429Z  \n",
       "2   2022-04-25T22:23:17.284Z  \n",
       "3   2022-04-25T22:24:06.328Z  \n",
       "4   2022-04-25T22:23:49.388Z  \n",
       "..                       ...  \n",
       "95  2022-04-25T22:24:10.774Z  \n",
       "96  2022-04-25T22:25:21.188Z  \n",
       "97  2022-04-25T22:24:12.030Z  \n",
       "98  2022-04-25T22:24:24.243Z  \n",
       "99  2022-04-25T22:24:53.035Z  \n",
       "\n",
       "[100 rows x 26 columns]"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(cg.get_coins_markets(vs_currency=\"eur\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5. Get all the supported crypto exchanges:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>year_established</th>\n",
       "      <th>country</th>\n",
       "      <th>description</th>\n",
       "      <th>url</th>\n",
       "      <th>image</th>\n",
       "      <th>has_trading_incentive</th>\n",
       "      <th>trust_score</th>\n",
       "      <th>trust_score_rank</th>\n",
       "      <th>trade_volume_24h_btc</th>\n",
       "      <th>trade_volume_24h_btc_normalized</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>binance</td>\n",
       "      <td>Binance</td>\n",
       "      <td>2017.0</td>\n",
       "      <td>Cayman Islands</td>\n",
       "      <td></td>\n",
       "      <td>https://www.binance.com/</td>\n",
       "      <td>https://assets.coingecko.com/markets/images/52...</td>\n",
       "      <td>False</td>\n",
       "      <td>10.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>460962.137271</td>\n",
       "      <td>460962.137271</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>okex</td>\n",
       "      <td>OKX</td>\n",
       "      <td>2013.0</td>\n",
       "      <td>Belize</td>\n",
       "      <td></td>\n",
       "      <td>https://www.okx.com</td>\n",
       "      <td>https://assets.coingecko.com/markets/images/96...</td>\n",
       "      <td>False</td>\n",
       "      <td>10.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>96523.691151</td>\n",
       "      <td>96523.691151</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>gdax</td>\n",
       "      <td>Coinbase Exchange</td>\n",
       "      <td>2012.0</td>\n",
       "      <td>United States</td>\n",
       "      <td></td>\n",
       "      <td>https://www.coinbase.com</td>\n",
       "      <td>https://assets.coingecko.com/markets/images/23...</td>\n",
       "      <td>False</td>\n",
       "      <td>10.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>81675.659788</td>\n",
       "      <td>81675.659788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>kucoin</td>\n",
       "      <td>KuCoin</td>\n",
       "      <td>2014.0</td>\n",
       "      <td>Seychelles</td>\n",
       "      <td></td>\n",
       "      <td>https://www.kucoin.com/</td>\n",
       "      <td>https://assets.coingecko.com/markets/images/61...</td>\n",
       "      <td>False</td>\n",
       "      <td>10.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>70408.647942</td>\n",
       "      <td>70408.647942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>gate</td>\n",
       "      <td>Gate.io</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Hong Kong</td>\n",
       "      <td>Gate was established in 2013, and it is the to...</td>\n",
       "      <td>https://gate.io/</td>\n",
       "      <td>https://assets.coingecko.com/markets/images/60...</td>\n",
       "      <td>False</td>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>62150.726708</td>\n",
       "      <td>62150.726708</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        id               name  year_established         country  \\\n",
       "0  binance            Binance            2017.0  Cayman Islands   \n",
       "1     okex                OKX            2013.0          Belize   \n",
       "2     gdax  Coinbase Exchange            2012.0   United States   \n",
       "3   kucoin             KuCoin            2014.0      Seychelles   \n",
       "4     gate            Gate.io               NaN       Hong Kong   \n",
       "\n",
       "                                         description  \\\n",
       "0                                                      \n",
       "1                                                      \n",
       "2                                                      \n",
       "3                                                      \n",
       "4  Gate was established in 2013, and it is the to...   \n",
       "\n",
       "                        url  \\\n",
       "0  https://www.binance.com/   \n",
       "1       https://www.okx.com   \n",
       "2  https://www.coinbase.com   \n",
       "3   https://www.kucoin.com/   \n",
       "4          https://gate.io/   \n",
       "\n",
       "                                               image has_trading_incentive  \\\n",
       "0  https://assets.coingecko.com/markets/images/52...                 False   \n",
       "1  https://assets.coingecko.com/markets/images/96...                 False   \n",
       "2  https://assets.coingecko.com/markets/images/23...                 False   \n",
       "3  https://assets.coingecko.com/markets/images/61...                 False   \n",
       "4  https://assets.coingecko.com/markets/images/60...                 False   \n",
       "\n",
       "   trust_score  trust_score_rank  trade_volume_24h_btc  \\\n",
       "0         10.0               1.0         460962.137271   \n",
       "1         10.0               2.0          96523.691151   \n",
       "2         10.0               3.0          81675.659788   \n",
       "3         10.0               4.0          70408.647942   \n",
       "4         10.0               5.0          62150.726708   \n",
       "\n",
       "   trade_volume_24h_btc_normalized  \n",
       "0                    460962.137271  \n",
       "1                     96523.691151  \n",
       "2                     81675.659788  \n",
       "3                     70408.647942  \n",
       "4                     62150.726708  "
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "exchanges_df = pd.DataFrame(cg.get_exchanges_list(per_page=250))\n",
    "exchanges_df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6. Get a summary of DEFI:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'defi_market_cap': '118949637319.874721498878154217',\n",
       " 'eth_market_cap': '362878286359.5266097022944933676',\n",
       " 'defi_to_eth_ratio': '32.7794860676848949187041412290563546987479655139292506626907626',\n",
       " 'trading_volume_24h': '8086105196.01992223011241297138',\n",
       " 'defi_dominance': '6.0673547283151764961090911610960009692607355347723013',\n",
       " 'top_coin_name': 'Terra',\n",
       " 'top_coin_defi_dominance': 27.92948814210331}"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cg.get_global_decentralized_finance_defi()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.10 ('pff2')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "342px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  },
  "vscode": {
   "interpreter": {
    "hash": "0117835dafdb051235b33d006a7ad155411608685e1d44af6fb551f6db3e7774"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
